Beispiel #1
0
        private bool IsFileLoaded(string /*!*/ path, string /*!*/ fullPath, IEnumerable <string> appendExtensions)
        {
            var toPath          = _toStrStorage.GetSite(CompositeConversionAction.Make(_context, CompositeConversion.ToPathToStr));
            var encodedPath     = _context.EncodePath(path);
            var encodedFullPath = (fullPath != null) ? _context.EncodePath(fullPath) : null;

            foreach (object file in GetLoadedFiles())
            {
                if (file == null)
                {
                    throw RubyExceptions.CreateTypeConversionError("nil", "String");
                }

                // use case sensitive comparison
                MutableString loadedFile = Protocols.CastToPath(toPath, file);
                if (loadedFile.Equals(encodedPath) || loadedFile.Equals(encodedFullPath))
                {
                    return(true);
                }

                if (appendExtensions != null)
                {
                    foreach (var extension in appendExtensions)
                    {
                        var pathWithExtension = _context.EncodePath(path + extension);
                        if (loadedFile.Equals(pathWithExtension) || loadedFile.Equals(encodedFullPath))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Beispiel #2
0
        public CompositeConversionAction /*!*/ CompositeConversion(CompositeConversion conversion)
        {
            var key = conversion;

            lock (_conversionActions) {
                CompositeConversionAction result;
                if (!_compositeConversionActions.TryGetValue(key, out result))
                {
                    _compositeConversionActions.Add(key, result = CompositeConversionAction.Make(_context, conversion));
                }
                return(result);
            }
        }
Beispiel #3
0
        internal string[] /*!*/ GetLoadPathStrings()
        {
            var loadPaths = GetLoadPaths();
            var result    = new string[loadPaths.Length];
            var toPath    = _toStrStorage.GetSite(CompositeConversionAction.Make(_context, CompositeConversion.ToPathToStr));

            for (int i = 0; i < loadPaths.Length; i++)
            {
                if (loadPaths[i] == null)
                {
                    throw RubyExceptions.CreateTypeConversionError("nil", "String");
                }

                result[i] = Protocols.CastToPath(toPath, loadPaths[i]).ConvertToString();
            }

            return(result);
        }
Beispiel #4
0
        private bool AnyFileLoaded(IEnumerable <MutableString> /*!*/ paths)
        {
            var toPath = _toStrStorage.GetSite(CompositeConversionAction.Make(_context, CompositeConversion.ToPathToStr));

            foreach (object file in GetLoadedFiles())
            {
                if (file == null)
                {
                    throw RubyExceptions.CreateTypeConversionError("nil", "String");
                }

                // use case sensitive comparison
                MutableString loadedPath = Protocols.CastToPath(toPath, file);
                if (paths.Any((path) => loadedPath.Equals(path)))
                {
                    return(true);
                }
            }

            return(false);
        }
        public static object Reinitialize(ConversionStorage <Union <IList, int> > /*!*/ toAryToInt,
                                          BlockParam block, RubyArray /*!*/ self, [NotNull] object /*!*/ arrayOrSize)
        {
            var context = toAryToInt.Context;

            var site  = toAryToInt.GetSite(CompositeConversionAction.Make(context, CompositeConversion.ToAryToInt));
            var union = site.Target(site, arrayOrSize);

            if (union.First != null)
            {
                // block ignored
                return(Reinitialize(self, union.First));
            }
            else if (block != null)
            {
                return(Reinitialize(block, self, union.Second));
            }
            else
            {
                return(ReinitializeByRepeatedValue(context, self, union.Second, null));
            }
        }
        public static object CreateArray(ConversionStorage <Union <IList, int> > /*!*/ toAryToInt,
                                         BlockParam block, RubyClass /*!*/ self, [NotNull] object /*!*/ arrayOrSize)
        {
            var site  = toAryToInt.GetSite(CompositeConversionAction.Make(toAryToInt.Context, CompositeConversion.ToAryToInt));
            var union = site.Target(site, arrayOrSize);


            if (union.First != null)
            {
                // block ignored
                // TODO: implement copy-on-write
                return(new RubyArray(union.First));
            }
            else if (block != null)
            {
                return(CreateArray(block, union.Second));
            }
            else
            {
                return(CreateArray(self, union.Second, null));
            }
        }
Beispiel #7
0
        public static IntegerValue ConvertToInteger(ConversionStorage <IntegerValue> /*!*/ integerConversion, object value)
        {
            var site = integerConversion.GetSite(CompositeConversionAction.Make(integerConversion.Context, CompositeConversion.ToIntToI));

            return(site.Target(site, value));
        }
Beispiel #8
0
 /// <summary>
 /// Converts an object to string using to_path-to_str protocol.
 /// Protocol:
 /// ? to_path => to_path() and to_str conversion on the result
 /// ? to_str => to_str()
 /// </summary>
 public static MutableString /*!*/ CastToPath(ConversionStorage <MutableString> /*!*/ toPath, object obj)
 {
     return(CastToPath(toPath.GetSite(CompositeConversionAction.Make(toPath.Context, CompositeConversion.ToPathToStr)), obj));
 }
        public IntegerValue ConvertToInteger(object value)
        {
            var site = RubyUtils.GetCallSite(ref _integerConversion, CompositeConversionAction.Make(Context, CompositeConversion.ToIntToI));

            return(site.Target(site, value));
        }