Package org.jruby.runtime.load

Examples of org.jruby.runtime.load.LoadService$AlreadyLoaded


    }

    @JRubyMethod(name = "autoload", required = 2, frame = true, module = true, visibility = PRIVATE)
    public static IRubyObject autoload(final IRubyObject recv, IRubyObject symbol, final IRubyObject file) {
        Ruby runtime = recv.getRuntime();
        final LoadService loadService = runtime.getLoadService();
        String nonInternedName = symbol.asJavaString();
       
        if (!IdUtil.isValidConstantName(nonInternedName)) {
            throw runtime.newNameError("autoload must be constant name", nonInternedName);
        }
       
        RubyString fileString = file.convertToString();
       
        if (fileString.isEmpty()) {
            throw runtime.newArgumentError("empty file name");
        }
       
        final String baseName = symbol.asJavaString().intern(); // interned, OK for "fast" methods
        final RubyModule module = recv instanceof RubyModule ? (RubyModule) recv : runtime.getObject();
        String nm = module.getName() + "::" + baseName;
       
        IRubyObject existingValue = module.fastFetchConstant(baseName);
        if (existingValue != null && existingValue != RubyObject.UNDEF) return runtime.getNil();
       
        module.fastStoreConstant(baseName, RubyObject.UNDEF);
       
        loadService.addAutoload(nm, new IAutoloadMethod() {
            public String file() {
                return file.toString();
            }
            /**
             * @see org.jruby.runtime.load.IAutoloadMethod#load(Ruby, String)
             */
            public IRubyObject load(Ruby runtime, String name) {
                boolean required = loadService.require(file());
               
                // File to be loaded by autoload has already been or is being loaded.
                if (!required) return null;
               
                return module.fastGetConstant(baseName);
View Full Code Here


    }

    @JRubyMethod(required = 2, module = true, visibility = PRIVATE)
    public static IRubyObject autoload(final IRubyObject recv, IRubyObject symbol, final IRubyObject file) {
        Ruby runtime = recv.getRuntime();
        final LoadService loadService = runtime.getLoadService();
        String nonInternedName = symbol.asJavaString();
       
        if (!IdUtil.isValidConstantName(nonInternedName)) {
            throw runtime.newNameError("autoload must be constant name", nonInternedName);
        }

        if (!runtime.is1_9() && !(file instanceof RubyString)) throw runtime.newTypeError(file, runtime.getString());

        RubyString fileString = RubyFile.get_path(runtime.getCurrentContext(), file);
       
        if (fileString.isEmpty()) throw runtime.newArgumentError("empty file name");
       
        final String baseName = symbol.asJavaString().intern(); // interned, OK for "fast" methods
        final RubyModule module = getModuleForAutoload(runtime, recv);
        String nm = module.getName() + "::" + baseName;
       
        IRubyObject existingValue = module.fastFetchConstant(baseName);
        if (existingValue != null && existingValue != RubyObject.UNDEF) return runtime.getNil();

        module.fastStoreConstant(baseName, RubyObject.UNDEF);

        loadService.addAutoload(nm, new IAutoloadMethod() {
            public String file() {
                return file.toString();
            }
            /**
             * @see org.jruby.runtime.load.IAutoloadMethod#load(Ruby, String)
             */
            public IRubyObject load(Ruby runtime, String name) {
                boolean required = loadService.require(file());
               
                // File to be loaded by autoload has already been or is being loaded.
                if (!required) return null;
               
                return module.fastGetConstant(baseName);
View Full Code Here

        list.add("lib/ruby/1.8");
        final List finalList = list;
        // runtime.getLoadService().init(list);
        // Allow privileged access to ready properties. Requires PropertyPermission in security
        // policy.
        final LoadService loadService = runtime.getLoadService();
        AccessController.doPrivileged(new PrivilegedAction<Object>() {
            public Ruby run() {
                loadService.init(finalList);
                // loadService.require("java");
                return null;
            }
        });       
    }
View Full Code Here

TOP

Related Classes of org.jruby.runtime.load.LoadService$AlreadyLoaded

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.