org.jruby.RubyClass Java Examples

The following examples show how to use org.jruby.RubyClass. 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: RubyScriptTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Test(enabled = false)
public void resultsCapturesJavaError() throws Exception {
    RubyScript script = new RubyScript(out, err, converToCode(SCRIPT_CONTENTS_ERROR_FROM_JAVA),
            new File(System.getProperty(Constants.PROP_PROJECT_DIR), "dummyfile.rb").getAbsolutePath(), false, null,
            Constants.FRAMEWORK_SWING);
    script.setDriverURL("");
    Ruby interpreter = script.getInterpreter();
    assertTrue("Collector not defined", interpreter.isClassDefined("Collector"));
    RubyClass collectorClass = interpreter.getClass("Collector");
    IRubyObject presult = JavaEmbedUtils.javaToRuby(interpreter, result);
    IRubyObject collector = collectorClass.newInstance(interpreter.getCurrentContext(), new IRubyObject[0], new Block(null));
    IRubyObject rubyObject = interpreter.evalScriptlet("proc { my_function }");
    try {
        collector.callMethod(interpreter.getCurrentContext(), "callprotected", new IRubyObject[] { rubyObject, presult });
    } catch (Throwable t) {

    }
    assertEquals(1, result.failureCount());
    Failure[] failures = result.failures();
    assertTrue("Should end with TestRubyScript.java. but has " + failures[0].getTraceback()[0].fileName,
            failures[0].getTraceback()[0].fileName.endsWith("TestRubyScript.java"));
    assertEquals("throwError", failures[0].getTraceback()[0].functionName);
}
 
Example #2
Source File: RubyDataBag.java    From spork with Apache License 2.0 6 votes vote down vote up
/**
 * This method registers the class with the given runtime. It is not necessary to do this here,
 * but it is simpler to associate the methods necessary to register the class with the class
 * itself, so on the Library side it is possible to just specify "RubyDataBag.define(runtime)".
 *
 * @param runtime an instance of the Ruby runtime
 * @return        a RubyClass object with metadata about the registered class
 */
public static RubyClass define(Ruby runtime) {
    // This generates the class object associated with DataBag, and registers it with the
    // runtime. The RubyClass object has all the metadata associated with a Class itself.
    RubyClass result = runtime.defineClass("DataBag", runtime.getObject(), ALLOCATOR);

    // This registers a method which can be used to know whether a module is an
    // instance of the class.
    result.kindOf = new RubyModule.KindOf() {
        public boolean isKindOf(IRubyObject obj, RubyModule type) {
            return obj instanceof RubyDataBag;
        }
    };

    // This includes the Enumerable module that we specified.
    result.includeModule(runtime.getEnumerable());

    // This method actually reads the annotations we placed and registers
    // all of the methods.
    result.defineAnnotatedMethods(RubyDataBag.class);

    // This returns the RubyClass object with all the new metadata.
    return result;
}
 
Example #3
Source File: AbstractProcessorProxy.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
private static void handleFormatAnnotation(Class<? extends Processor> processor, RubyClass rubyClass) {
    Ruby rubyRuntime = rubyClass.getRuntime();
    if (processor.isAnnotationPresent(Format.class)) {
        Format format = processor.getAnnotation(Format.class);
        switch (format.value()) {
            case CUSTOM:
                rubyClass.callMethod(rubyRuntime.getCurrentContext(), "option", new IRubyObject[]{
                        rubyRuntime.newSymbol("regexp"),
                        convertRegexp(rubyRuntime, format.regexp())
                });
            default:
                rubyClass.callMethod(rubyRuntime.getCurrentContext(), "option", new IRubyObject[]{
                        rubyRuntime.newSymbol("format"),
                        rubyRuntime.newSymbol(format.value().optionValue().substring(1))
                });
        }
    }
}
 
Example #4
Source File: ConverterProxy.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
public static <U, T  extends Converter<U> & OutputFormatWriter<U>> RubyClass register(JRubyAsciidoctor asciidoctor, final Class<T> converterClass) {
    Ruby rubyRuntime = asciidoctor.getRubyRuntime();
    RubyModule module = rubyRuntime.defineModule(getModuleName(converterClass));
    RubyClass clazz = module.defineClassUnder(
            converterClass.getSimpleName(),
            rubyRuntime.getObject(),
            new ConverterProxy.Allocator(converterClass, asciidoctor));
    includeModule(clazz, "Asciidoctor", "Converter");
    includeModule(clazz, "Asciidoctor", "Converter", "BackendTraits");

    clazz.defineAnnotatedMethod(ConverterProxy.class, "initialize");
    clazz.defineAnnotatedMethod(ConverterProxy.class, "convert");

    includeModule(clazz, "Asciidoctor", "Writer");
    clazz.defineAnnotatedMethod(ConverterProxy.class, "write");

    //clazz.defineAnnotatedMethods(ConverterProxy.class);
    return clazz;
}
 
Example #5
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 #6
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 #7
Source File: ScriptUtils.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * instantiateClass
 * 
 * @param runtime
 * @param name
 * @param args
 * @return
 */
public static IRubyObject instantiateClass(Ruby runtime, String name, IRubyObject... args)
{
	ThreadContext threadContext = runtime.getCurrentContext();
	IRubyObject result = null;

	// try to load the class
	RubyClass rubyClass = runtime.getClass(name);

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

	return result;
}
 
Example #8
Source File: JavaDissectorLibrary.java    From logstash-filter-dissect with Apache License 2.0 6 votes vote down vote up
@JRubyMethod(name = "initialize", required = 2, optional = 2)
public IRubyObject rubyInitialize(final ThreadContext ctx, final IRubyObject[] args) {
    final Ruby ruby = ctx.runtime;
    try {
        dissectors = DissectPair.createArrayFromHash((RubyHash) args[0]);
    } catch (final InvalidFieldException e) {
        throw new RaiseException(e, JavaDissectorLibrary.NativeExceptions.newFieldFormatError(ruby, e));
    }
    plugin = (RubyObject) args[1];
    pluginMetaClass = plugin.getMetaClass();
    conversions = ConvertPair.createArrayFromHash((RubyHash) args[2]);
    for (final ConvertPair convertPair : conversions) {
        if (convertPair.converter().isInvalid()) {
            final RubyClass klass = ruby.getModule("LogStash").getClass("ConvertDatatypeFormatError");
            final String errorMessage = String.format("Dissector datatype conversion, datatype not supported: %s", convertPair.type());
            throw new RaiseException(ruby, klass, errorMessage, true);
        }
    }
    runMatched = args[3] == null || args[3].isTrue();
    failureTags = fetchFailureTags(ctx);
    return ctx.nil;
}
 
Example #9
Source File: AbstractProcessorProxy.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
private static void handleDefaultAttributesAnnotation(Class<? extends Processor> processor, RubyClass rubyClass) {
    Ruby rubyRuntime = rubyClass.getRuntime();
    if (processor.isAnnotationPresent(DefaultAttributes.class)) {
        DefaultAttributes defaultAttributes = processor.getAnnotation(DefaultAttributes.class);
        RubyHash defaultAttrs = RubyHash.newHash(rubyRuntime);
        for (DefaultAttribute defaultAttribute : defaultAttributes.value()) {
            defaultAttrs.put(defaultAttribute.key(), defaultAttribute.value());
        }
        rubyClass.callMethod(rubyRuntime.getCurrentContext(), "option", new IRubyObject[]{
                rubyRuntime.newSymbol("default_attrs"),
                defaultAttrs
        });
    }
}
 
Example #10
Source File: ExtensionGroupImpl.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Override
public ExtensionGroup treeprocessor(final Class<? extends Treeprocessor> treeProcessor) {
  final RubyClass rubyClass = TreeprocessorProxy.register(asciidoctor, treeProcessor);
  registrators.add(new Registrator() {
    @Override
    public void register(IRubyObject registry) {
      registry.callMethod(rubyRuntime.getCurrentContext(), "tree_processor", rubyClass);
    }
  });
  return this;
}
 
Example #11
Source File: BlockProcessorProxy.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
public static RubyClass register(final JRubyAsciidoctor asciidoctor, final Class<? extends BlockProcessor> blockProcessor) {
    RubyClass rubyClass = ProcessorProxyUtil.defineProcessorClass(asciidoctor.getRubyRuntime(), "BlockProcessor", new JRubyAsciidoctorObjectAllocator(asciidoctor) {
        @Override
        public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
            return new BlockProcessorProxy(asciidoctor, klazz, blockProcessor);
        }
    });

    applyAnnotations(blockProcessor, rubyClass);

    ProcessorProxyUtil.defineAnnotatedMethods(rubyClass, BlockProcessorProxy.class);
    return rubyClass;
}
 
Example #12
Source File: ExtensionGroupImpl.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Override
public ExtensionGroup block(final String blockName, final BlockProcessor blockProcessor) {
  final RubyClass rubyClass = BlockProcessorProxy.register(asciidoctor, blockProcessor);
  registrators.add(new Registrator() {
    @Override
    public void register(IRubyObject registry) {
      registry.callMethod(rubyRuntime.getCurrentContext(), "block", new IRubyObject[]{rubyClass, rubyRuntime.newSymbol(blockName)});
    }
  });
  return this;
}
 
Example #13
Source File: ExtensionGroupImpl.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Override
public ExtensionGroup docinfoProcessor(final DocinfoProcessor docInfoProcessor) {
  final RubyClass rubyClass = DocinfoProcessorProxy.register(asciidoctor, docInfoProcessor);
  registrators.add(new Registrator() {
    @Override
    public void register(IRubyObject registry) {
      registry.callMethod(rubyRuntime.getCurrentContext(), "docinfo_processor", rubyClass);
    }
  });
  return this;
}
 
Example #14
Source File: JavaExtensionRegistryImpl.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Override
public JavaExtensionRegistry blockMacro(Class<? extends BlockMacroProcessor> blockMacroProcessor) {
    String name = getName(blockMacroProcessor);
    RubyClass rubyClass = BlockMacroProcessorProxy.register(asciidoctor, blockMacroProcessor);
    getAsciidoctorModule().callMethod("block_macro", rubyClass, rubyRuntime.newString(name));
    return this;
}
 
Example #15
Source File: IncludeProcessorProxy.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
public static RubyClass register(final JRubyAsciidoctor asciidoctor, final IncludeProcessor includeProcessor) {
    RubyClass rubyClass = ProcessorProxyUtil.defineProcessorClass(asciidoctor.getRubyRuntime(), "IncludeProcessor", new JRubyAsciidoctorObjectAllocator(asciidoctor) {
        @Override
        public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
            return new IncludeProcessorProxy(asciidoctor, klazz, includeProcessor);
        }
    });

    applyAnnotations(includeProcessor.getClass(), rubyClass);

    ProcessorProxyUtil.defineAnnotatedMethods(rubyClass, IncludeProcessorProxy.class);
    return rubyClass;
}
 
Example #16
Source File: TreeprocessorProxy.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
public static RubyClass register(final JRubyAsciidoctor asciidoctor, final Class<? extends Treeprocessor> treeProcessor) {
    RubyClass rubyClass = ProcessorProxyUtil.defineProcessorClass(asciidoctor.getRubyRuntime(), "Treeprocessor", new JRubyAsciidoctorObjectAllocator(asciidoctor) {
        @Override
        public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
            return new TreeprocessorProxy(asciidoctor, klazz, treeProcessor);
        }
    });

    applyAnnotations(treeProcessor, rubyClass);

    rubyClass.defineAnnotatedMethods(TreeprocessorProxy.class);
    return rubyClass;
}
 
Example #17
Source File: TreeprocessorProxy.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
public static RubyClass register(final JRubyAsciidoctor asciidoctor, final Treeprocessor treeProcessor) {
    RubyClass rubyClass = ProcessorProxyUtil.defineProcessorClass(asciidoctor.getRubyRuntime(), "Treeprocessor", new JRubyAsciidoctorObjectAllocator(asciidoctor) {
        @Override
        public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
            return new TreeprocessorProxy(this.asciidoctor, klazz, treeProcessor);
        }
    });

    applyAnnotations(treeProcessor.getClass(), rubyClass);

    rubyClass.defineAnnotatedMethods(TreeprocessorProxy.class);
    return rubyClass;
}
 
Example #18
Source File: DocinfoProcessorProxy.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
public static RubyClass register(final JRubyAsciidoctor asciidoctor, final DocinfoProcessor docinfoProcessor) {
    RubyClass rubyClass = ProcessorProxyUtil.defineProcessorClass(asciidoctor.getRubyRuntime(), "DocinfoProcessor", new JRubyAsciidoctorObjectAllocator(asciidoctor) {
        @Override
        public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
            return new DocinfoProcessorProxy(asciidoctor, klazz, docinfoProcessor);
        }
    });

    applyAnnotations(docinfoProcessor.getClass(), rubyClass);

    ProcessorProxyUtil.defineAnnotatedMethods(rubyClass, DocinfoProcessorProxy.class);
    return rubyClass;
}
 
Example #19
Source File: AbstractProcessorProxy.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
private static void handlePositionalAttributesAnnotation(Class<? extends Processor> processor, RubyClass rubyClass) {
    Ruby rubyRuntime = rubyClass.getRuntime();
    if (processor.isAnnotationPresent(PositionalAttributes.class)) {
        PositionalAttributes positionalAttributes = processor.getAnnotation(PositionalAttributes.class);
        RubyArray positionalAttrs = RubyArray.newArray(rubyRuntime);
        for (String positionalAttribute : positionalAttributes.value()) {
            positionalAttrs.add(positionalAttribute);
        }
        rubyClass.callMethod(rubyRuntime.getCurrentContext(), "option", new IRubyObject[]{
                rubyRuntime.newSymbol("positional_attrs"),
                positionalAttrs
        });
    }
}
 
Example #20
Source File: SyntaxHighlighterProxy.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
public static <T extends SyntaxHighlighterAdapter> RubyClass register(JRubyAsciidoctor asciidoctor, final Class<T> highlighterClass) {
  Ruby rubyRuntime = asciidoctor.getRubyRuntime();
  RubyModule module = rubyRuntime.defineModule(getModuleName(highlighterClass));

  RubyClass syntaxHighlighterBase = rubyRuntime.getModule("Asciidoctor")
      .getModule("SyntaxHighlighter")
      .getClass("Base");

  RubyClass clazz = module.defineClassUnder(
      highlighterClass.getSimpleName(),
      syntaxHighlighterBase,
      new SyntaxHighlighterProxy.Allocator(highlighterClass, asciidoctor));

  clazz.defineAnnotatedMethod(SyntaxHighlighterProxy.class, "initialize");
  clazz.defineAnnotatedMethod(SyntaxHighlighterProxy.class, "hasDocInfo");
  clazz.defineAnnotatedMethod(SyntaxHighlighterProxy.class, "getDocInfo");

  if (StylesheetWriter.class.isAssignableFrom(highlighterClass)) {
    clazz.defineAnnotatedMethod(SyntaxHighlighterProxy.class, "isWriteStylesheet");
    clazz.defineAnnotatedMethod(SyntaxHighlighterProxy.class, "writeStylesheet");
  }

  if (Highlighter.class.isAssignableFrom(highlighterClass)) {
    clazz.defineAnnotatedMethod(SyntaxHighlighterProxy.class, "isHighlight");
    clazz.defineAnnotatedMethod(SyntaxHighlighterProxy.class, "highlight");
  }

  if (Formatter.class.isAssignableFrom(highlighterClass)) {
    clazz.defineAnnotatedMethod(SyntaxHighlighterProxy.class, "format");
  }

  return clazz;
}
 
Example #21
Source File: PostprocessorProxy.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
public static RubyClass register(final JRubyAsciidoctor asciidoctor, final Class<? extends Postprocessor> postprocessor) {
    RubyClass rubyClass = ProcessorProxyUtil.defineProcessorClass(asciidoctor.getRubyRuntime(), "Postprocessor", new JRubyAsciidoctorObjectAllocator(asciidoctor) {
        @Override
        public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
            return new PostprocessorProxy(asciidoctor, klazz, postprocessor);
        }
    });

    applyAnnotations(postprocessor, rubyClass);

    ProcessorProxyUtil.defineAnnotatedMethods(rubyClass, PostprocessorProxy.class);
    return rubyClass;
}
 
Example #22
Source File: PreprocessorProxy.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
public static RubyClass register(final JRubyAsciidoctor asciidoctor, final Class<? extends Preprocessor> preprocessor) {
    RubyClass rubyClass = ProcessorProxyUtil.defineProcessorClass(asciidoctor.getRubyRuntime(), "Preprocessor", new JRubyAsciidoctorObjectAllocator(asciidoctor) {
        @Override
        public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
            return new PreprocessorProxy(asciidoctor, klazz, preprocessor);
        }
    });

    applyAnnotations(preprocessor, rubyClass);

    ProcessorProxyUtil.defineAnnotatedMethods(rubyClass, PreprocessorProxy.class);
    return rubyClass;
}
 
Example #23
Source File: AbstractProcessorProxy.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
private static void handleContextsAnnotation(Class<? extends Processor> processor, RubyClass rubyClass) {
    Ruby rubyRuntime = rubyClass.getRuntime();
    if (processor.isAnnotationPresent(Contexts.class)) {
        Contexts contexts = processor.getAnnotation(Contexts.class);
        RubyArray contextList = rubyRuntime.newArray();
        for (String value : contexts.value()) {
            contextList.add(rubyRuntime.newSymbol(value.substring(1)));
        }
        rubyClass.callMethod(rubyRuntime.getCurrentContext(), "option", new IRubyObject[]{
                rubyRuntime.newSymbol("contexts"),
                contextList
        });

    }
}
 
Example #24
Source File: JavaDissectorLibrary.java    From logstash-filter-dissect with Apache License 2.0 5 votes vote down vote up
@Override
public final void load(final Ruby runtime, final boolean wrap) {
    final RubyModule module = runtime.defineModule("LogStash");

    final RubyClass clazz = runtime.defineClassUnder("Dissector", runtime.getObject(), JavaDissectorLibrary.RubyDissect::new, module);
    clazz.defineAnnotatedMethods(JavaDissectorLibrary.RubyDissect.class);

    final RubyClass runtimeError = runtime.getRuntimeError();
    module.defineClassUnder("FieldFormatError", runtimeError, runtimeError.getAllocator());
    module.defineClassUnder("ConvertDatatypeFormatError", runtimeError, runtimeError.getAllocator());
}
 
Example #25
Source File: PreprocessorProxy.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
public static RubyClass register(final JRubyAsciidoctor asciidoctor, final Preprocessor preprocessor) {
    RubyClass rubyClass = ProcessorProxyUtil.defineProcessorClass(asciidoctor.getRubyRuntime(), "Preprocessor", new JRubyAsciidoctorObjectAllocator(asciidoctor) {
        @Override
        public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
            return new PreprocessorProxy(asciidoctor, klazz, preprocessor);
        }
    });

    applyAnnotations(preprocessor.getClass(), rubyClass);

    ProcessorProxyUtil.defineAnnotatedMethods(rubyClass, PreprocessorProxy.class);
    return rubyClass;
}
 
Example #26
Source File: AbstractProcessorProxy.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
public AbstractProcessorProxy(JRubyAsciidoctor asciidoctor, RubyClass metaClass, T processor) {
    super(asciidoctor.getRubyRuntime(), metaClass);
    this.asciidoctor = asciidoctor;
    processor.unwrap(JRubyProcessor.class).setAsciidoctor(asciidoctor);
    this.processor = processor;
    this.processorDelegate = processor.unwrap(JRubyProcessor.class);
}
 
Example #27
Source File: ProcessorProxyUtil.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
/**
 * Defines the annotated methods of the given class and all super classes as
 * {@link org.jruby.RubyClass#defineAnnotatedMethods(Class)} does not handle inherited methods.
 * @param rubyClass
 * @param proxyClass
 */
public static void defineAnnotatedMethods(RubyClass rubyClass, Class<?> proxyClass) {
    Class<?> currentClass = proxyClass;
    while (currentClass != RubyObject.class) {
        rubyClass.defineAnnotatedMethods(currentClass);
        currentClass = currentClass.getSuperclass();
    }
}
 
Example #28
Source File: JavaConverterRegistryImpl.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Override
public Class<?> resolve(String backend) {
    RubyClass rubyClass = (RubyClass) getConverterFactory()
        .callMethod("for", rubyRuntime.newString(backend));

    Class<?> clazz = rubyClass.getReifiedClass();
    if (clazz != null) {
        return clazz;
    } else if (rubyClass.getAllocator() instanceof ConverterProxy.Allocator) {
        ConverterProxy.Allocator allocator = (ConverterProxy.Allocator) rubyClass.getAllocator();
        return allocator.getConverterClass();
    }
    return null;
}
 
Example #29
Source File: PostprocessorProxy.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
public static RubyClass register(final JRubyAsciidoctor asciidoctor, final Postprocessor postprocessor) {
    RubyClass rubyClass = ProcessorProxyUtil.defineProcessorClass(asciidoctor.getRubyRuntime(), "Postprocessor", new JRubyAsciidoctorObjectAllocator(asciidoctor) {
        @Override
        public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
            return new PostprocessorProxy(asciidoctor, klazz, postprocessor);
        }
    });

    applyAnnotations(postprocessor.getClass(), rubyClass);

    ProcessorProxyUtil.defineAnnotatedMethods(rubyClass, PostprocessorProxy.class);
    return rubyClass;
}
 
Example #30
Source File: SyntaxHighlighterRegistryImpl.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Override
public void register(final Class<? extends SyntaxHighlighterAdapter> highlighterClass, String... names) {

    RubyClass clazz = SyntaxHighlighterProxy.register(asciidoctor, highlighterClass);

    getSyntaxHighlighterFactory()
        .callMethod("register", clazz, rubyRuntime.newString(names[0]));
}