Java Code Examples for org.jruby.RubyClass#getRuntime()

The following examples show how to use org.jruby.RubyClass#getRuntime() . 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: 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 2
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 3
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 4
Source File: AbstractProcessorProxy.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
private static void handleDefaultAttributeAnnotation(Class<? extends Processor> processor, RubyClass rubyClass) {
    Ruby rubyRuntime = rubyClass.getRuntime();
    if (processor.isAnnotationPresent(DefaultAttribute.class)) {
        DefaultAttribute defaultAttribute = processor.getAnnotation(DefaultAttribute.class);
        RubyHash defaultAttrs = RubyHash.newHash(rubyRuntime);
        defaultAttrs.put(defaultAttribute.key(), defaultAttribute.value());
        rubyClass.callMethod(rubyRuntime.getCurrentContext(), "option", new IRubyObject[]{
                rubyRuntime.newSymbol("default_attrs"),
                defaultAttrs
        });
    }
}
 
Example 5
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 6
Source File: AbstractProcessorProxy.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
private static void handleContentModelAnnotation(Class<? extends Processor> processor, RubyClass rubyClass) {
    Ruby rubyRuntime = rubyClass.getRuntime();
    if (processor.isAnnotationPresent(ContentModel.class)) {
        ContentModel contentModel = processor.getAnnotation(ContentModel.class);
        rubyClass.callMethod(rubyRuntime.getCurrentContext(), "option", new IRubyObject[]{
                rubyRuntime.newSymbol("content_model"),
                rubyRuntime.newSymbol(contentModel.value().substring(1))
        });
    }
}
 
Example 7
Source File: AbstractProcessorProxy.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
private static void handleNameAnnotation(Class<? extends Processor> processor, RubyClass rubyClass) {
    Ruby rubyRuntime = rubyClass.getRuntime();
    if (processor.isAnnotationPresent(Name.class)) {
        Name name = processor.getAnnotation(Name.class);
        rubyClass.callMethod(rubyRuntime.getCurrentContext(), "option", new IRubyObject[]{
                rubyRuntime.newSymbol("name"),
                rubyRuntime.newString(name.value())
        });
    }
}
 
Example 8
Source File: AbstractProcessorProxy.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
private static void handleLocationAnnotation(Class<? extends Processor> processor, RubyClass rubyClass) {
    Ruby rubyRuntime = rubyClass.getRuntime();
    if (processor.isAnnotationPresent(Location.class)) {
        Location location = processor.getAnnotation(Location.class);
        rubyClass.callMethod(rubyRuntime.getCurrentContext(), "option", new IRubyObject[]{
                rubyRuntime.newSymbol("location"),
                rubyRuntime.newSymbol(location.value().optionValue().substring(1))
        });
    }
}