Java Code Examples for org.jruby.RubyModule#getClass()

The following examples show how to use org.jruby.RubyModule#getClass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScriptUtils.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * instantiateClass
 * 
 * @param runtime
 * @param module
 * @param name
 * @param args
 * @return
 */
public static IRubyObject instantiateClass(Ruby runtime, String module, String name, IRubyObject... args)
{
	ThreadContext threadContext = runtime.getCurrentContext();
	IRubyObject result = null;

	// try to load the module
	RubyModule rubyModule = runtime.getModule(module);

	if (rubyModule != null)
	{
		// now try to load the class
		RubyClass rubyClass = rubyModule.getClass(name);

		// instantiate it, if it exists
		if (rubyClass != null)
		{
			result = rubyClass.newInstance(threadContext, args, Block.NULL_BLOCK);
		}
	}

	return result;
}
 
Example 2
Source File: NodeConverter.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
public RubyClass getRubyClass(Ruby runtime) {

            if (path.length == 1) {
                return runtime.getClass(path[0]);
            } else {
                RubyModule object = runtime.getModule(path[0]);

                RubyClass rubyClass = object.getClass(path[1]);

                if (path.length == 2) {
                    return rubyClass;
                } else {
                    return rubyClass.getClass(path[2]);
                }
            }
        }
 
Example 3
Source File: RubyOutputStreamWrapper.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
public static RubyClass getOrCreateOutputStreamWrapperClass(final Ruby rubyRuntime) {
  RubyModule asciidoctorModule = rubyRuntime.getModule("AsciidoctorJ");
  RubyClass outputStreamWrapperClass = asciidoctorModule.getClass(RUBY_CLASS_NAME);
  if (outputStreamWrapperClass != null) {
    return outputStreamWrapperClass;
  }

  final RubyClass rubyClass = asciidoctorModule.defineClassUnder(RUBY_CLASS_NAME, rubyRuntime.getObject(), new ObjectAllocator() {
    @Override
    public IRubyObject allocate(final Ruby runtime, final RubyClass klazz) {
      return new RubyOutputStreamWrapper(runtime, klazz);
    }
  });

  rubyClass.defineAnnotatedMethods(RubyOutputStreamWrapper.class);

  return rubyClass;
}
 
Example 4
Source File: JRubyRackInput.java    From rack-servlet with Apache License 2.0 5 votes vote down vote up
private static RubyClass getRackInputClass(Ruby runtime) {
  RubyModule module = runtime.getOrCreateModule("RackServlet");
  RubyClass klass = module.getClass("RackInput");
  if (klass == null) {
    klass = module.defineClassUnder("RackInput", runtime.getObject(), ALLOCATOR);
    klass.defineAnnotatedMethods(JRubyRackInput.class);
  }
  return klass;
}
 
Example 5
Source File: ProcessorProxyUtil.java    From asciidoctorj with Apache License 2.0 2 votes vote down vote up
/**
 * For a simple Ruby class name like "Treeprocessor" it returns the associated RubyClass
 * from Asciidoctor::Extensions, e.g. Asciidoctor::Extensions::Treeprocessor
 * @param rubyRuntime
 * @param processorClassName
 * @return The Ruby class object for the given extension class name, e.g. Asciidoctor::Extensions::TreeProcessor
 */
public static RubyClass getExtensionBaseClass(Ruby rubyRuntime, String processorClassName) {
    RubyModule extensionsModule = getExtensionsModule(rubyRuntime);
    return extensionsModule.getClass(processorClassName);
}