Refine search
public static void createRubyDescriptor(Ruby runtime) { RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf"); RubyClass cDescriptor = protobuf.defineClassUnder("Descriptor", runtime.getObject(), new ObjectAllocator() { @Override public IRubyObject allocate(Ruby runtime, RubyClass klazz) { return new RubyDescriptor(runtime, klazz); } }); cDescriptor.includeModule(runtime.getEnumerable()); cDescriptor.defineAnnotatedMethods(RubyDescriptor.class); }
private RubyModule buildModuleFromDescriptor(ThreadContext context) { Ruby runtime = context.runtime; Utils.checkNameAvailability(context, name.asJavaString()); RubyModule enumModule = RubyModule.newModule(runtime); for (Descriptors.EnumValueDescriptor value : descriptor.getValues()) { enumModule.defineConstant(value.getName(), runtime.newFixnum(value.getNumber())); } enumModule.instance_variable_set(runtime.newString(Utils.DESCRIPTOR_INSTANCE_VAR), this); enumModule.defineAnnotatedMethods(RubyEnum.class); return enumModule; }
public static void createRubyOneofBuilderContext(Ruby runtime) { RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf"); RubyModule internal = protobuf.defineModuleUnder("Internal"); RubyClass cRubyOneofBuidlerContext = internal.defineClassUnder("OneofBuilderContext", runtime.getObject(), new ObjectAllocator() { @Override public IRubyObject allocate(Ruby ruby, RubyClass rubyClass) { return new RubyOneofBuilderContext(ruby, rubyClass); } }); cRubyOneofBuidlerContext.defineAnnotatedMethods(RubyOneofBuilderContext.class); }
public static void createProtobuf(Ruby runtime) { RubyModule mGoogle = runtime.getModule("Google"); RubyModule mProtobuf = mGoogle.defineModuleUnder("Protobuf"); mProtobuf.defineAnnotatedMethods(RubyProtobuf.class); }
public static void install(final Ruby runtime, final LogHandler logHandler) { final RubyModule asciidoctorModule = runtime.getModule("Asciidoctor"); final RubyModule loggerManager = asciidoctorModule.defineOrGetModuleUnder("LoggerManager"); final RubyClass loggerBaseClass = asciidoctorModule.getClass("Logger"); final RubyClass loggerClass = asciidoctorModule .defineOrGetModuleUnder("LoggerManager") .defineClassUnder("JavaLogger", loggerBaseClass, new ObjectAllocator() { @Override public IRubyObject allocate(Ruby runtime, RubyClass klazz) { return new JavaLogger(runtime, klazz, logHandler); } }); loggerClass.defineAnnotatedMethods(JavaLogger.class); final IRubyObject logger = loggerClass.allocate(); logger.callMethod(runtime.getCurrentContext(), "initialize", runtime.getNil()); loggerManager.callMethod("logger=", logger); }
public static RubyClass createEnumsClass(Ruby runtime, RubyModule ffiModule) { RubyClass enumsClass = ffiModule.defineClassUnder("Enums", runtime.getObject(), Allocator.INSTANCE); enumsClass.defineAnnotatedMethods(Enums.class); enumsClass.defineAnnotatedConstants(Enums.class); enumsClass.includeModule(ffiModule.getConstant("DataConverter")); return enumsClass; }
public static void createDigestBubbleBabble(Ruby runtime) { runtime.getLoadService().require("digest"); RubyModule Digest = runtime.getModule("Digest"); RubyClass Base = Digest.getClass("Base"); RubyClass MD5 = Digest.defineClassUnder("BubbleBabble", Base, Base.getAllocator()); MD5.setInternalVariable("metadata", new Metadata("BubbleBabble", 64)); }
@JRubyMethod(required = 2, optional = 1, frame = true) public static IRubyObject scalar(IRubyObject self, IRubyObject[] args, Block block) { Ruby runtime = self.getRuntime(); ThreadContext ctx = runtime.getCurrentContext(); IRubyObject type_id = args[0]; IRubyObject str = args[1]; IRubyObject style = args.length == 2 ? runtime.getNil() : args[2]; IRubyObject scalar = ((RubyModule)((RubyModule)runtime.getModule("YAML")).getConstant("Yecht")).getConstant("Scalar").callMethod(ctx, "new", new IRubyObject[]{type_id, str, style}); outMark((IRubyObject)((RubyObject)self).fastGetInstanceVariable("@emitter"), scalar); return scalar; } }
@JRubyMethod(name = "==", required = 1) public static IRubyObject op_equal(ThreadContext ctx, IRubyObject self, IRubyObject oth) { RubyString str1, str2; RubyModule instance = (RubyModule)self.getRuntime().getModule("Digest").getConstantAt("Instance"); if (oth.getMetaClass().getRealClass().hasModuleInHierarchy(instance)) { str1 = digest(ctx, self, null).convertToString(); str2 = digest(ctx, oth, null).convertToString(); } else { str1 = to_s(ctx, self).convertToString(); str2 = oth.convertToString(); } boolean ret = str1.length().eql(str2.length()) && (str1.eql(str2)); return ret ? self.getRuntime().getTrue() : self.getRuntime().getFalse(); }
@JRubyMethod(name = "initialize", visibility = PRIVATE, compat = RUBY2_0) public IRubyObject initialize20(ThreadContext context, IRubyObject object, Block block) { Ruby runtime = context.runtime; RubySymbol each = runtime.newSymbol("each"); // check for size if ((object.isNil() || runtime.getProc().isInstance(object)) || runtime.getFloat().isInstance(object) && ((RubyFloat)object).getDoubleValue() == Float.POSITIVE_INFINITY) { // object is nil, a proc, or infinity; use it for size IRubyObject gen = context.runtime.getModule("JRuby").getClass("Generator").callMethod(context, "new", new IRubyObject[0], block); return initialize20(gen, each, NULL_ARRAY, object); } return initialize(object, each, NULL_ARRAY); }
public static void create(Ruby runtime) { RubyModule mNet = runtime.getModule("Net"); RubyClass cBufferedIO = (RubyClass)mNet.getConstant("BufferedIO"); cBufferedIO.defineAnnotatedMethods(NetProtocolBufferedIO.class); RubyModule mNativeImpl = cBufferedIO.defineModuleUnder("NativeImplementation"); mNativeImpl.defineAnnotatedMethods(NativeImpl.class); }
public static void createRubyDescriptorPool(Ruby runtime) { RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf"); RubyClass cDescriptorPool = protobuf.defineClassUnder("DescriptorPool", runtime.getObject(), new ObjectAllocator() { @Override public IRubyObject allocate(Ruby runtime, RubyClass klazz) { return new RubyDescriptorPool(runtime, klazz); } }); cDescriptorPool.defineAnnotatedMethods(RubyDescriptorPool.class); descriptorPool = (RubyDescriptorPool) cDescriptorPool.newInstance(runtime.getCurrentContext(), Block.NULL_BLOCK); }
@JRubyMethod(name = "==", required = 1) public static IRubyObject op_equal(ThreadContext context, IRubyObject self, IRubyObject oth) { if(oth.isNil()) return context.fals; RubyString str1, str2; RubyModule instance = (RubyModule)context.runtime.getModule("Digest").getConstantAt("Instance"); if (oth.getMetaClass().getRealClass().hasModuleInHierarchy(instance)) { str1 = digest(context, self, null).convertToString(); str2 = digest(context, oth, null).convertToString(); } else { str1 = to_s(context, self).convertToString(); str2 = oth.convertToString(); } boolean ret = str1.bytesize().eql(str2.bytesize()) && (str1.eql(str2)); return ret ? context.tru : context.fals; }
public void load(Ruby runtime, boolean wrap) { runtime.getLoadService().require("java"); // load Ruby parts of the 'jruby' library runtime.getLoadService().loadFromClassLoader(runtime.getJRubyClassLoader(), "jruby/jruby.rb", false); RubyModule JRuby = runtime.getOrCreateModule("JRuby"); JRuby.defineAnnotatedMethods(JRubyLibrary.class); JRuby.defineAnnotatedMethods(JRubyUtilLibrary.class); JRuby.defineClassUnder("ThreadLocal", runtime.getObject(), JRubyThreadLocal.ALLOCATOR) .defineAnnotatedMethods(JRubyExecutionContextLocal.class); JRuby.defineClassUnder("FiberLocal", runtime.getObject(), JRubyFiberLocal.ALLOCATOR) .defineAnnotatedMethods(JRubyExecutionContextLocal.class); RubyModule CONFIG = JRuby.defineModuleUnder("CONFIG"); CONFIG.getSingletonClass().defineAnnotatedMethods(JRubyConfig.class); }
public void load(Ruby runtime, boolean wrap) throws IOException { RubyModule JRuby = runtime.getOrCreateModule("JRuby"); RubyModule JRubyUtil = JRuby.defineModuleUnder("Util"); JRubyUtil.defineAnnotatedMethods(JRubyUtilLibrary.class); JRubyUtil.setConstant("SEPARATOR", runtime.newString(org.jruby.util.cli.ArgumentProcessor.SEPARATOR)); JRubyUtil.setConstant("ON_WINDOWS", runtime.newBoolean(org.jruby.platform.Platform.IS_WINDOWS)); JRubyUtil.setConstant("ON_SOLARIS", runtime.newBoolean(org.jruby.platform.Platform.IS_SOLARIS)); }
public static RubyModule createMarshalModule(Ruby runtime) { RubyModule module = runtime.defineModule("Marshal"); runtime.setMarshal(module); module.defineAnnotatedMethods(RubyMarshal.class); module.defineConstant("MAJOR_VERSION", runtime.newFixnum(Constants.MARSHAL_MAJOR)); module.defineConstant("MINOR_VERSION", runtime.newFixnum(Constants.MARSHAL_MINOR)); return module; }
@Override public void register() { IRubyObject callback = extensionGroupClass.newInstance(rubyRuntime.getCurrentContext(), Block.NULL_BLOCK); asciidoctorModule.callMethod("register_extension_group", rubyRuntime.newString(this.groupName), callback, JavaEmbedUtils.javaToRuby(rubyRuntime, registrators)); }
private static void defineGroupStruct(Ruby runtime) { IRubyObject[] args = new IRubyObject[] { runtime.newString("Group"), runtime.newSymbol("name"), runtime.newSymbol("passwd"), runtime.newSymbol("gid"), runtime.newSymbol("mem") }; runtime.setGroupStruct(RubyStruct.newInstance(runtime.getStructClass(), args, Block.NULL_BLOCK)); runtime.getEtc().defineConstant("Group", runtime.getGroupStruct()); }
static RubyClass createJavaClassClass(final Ruby runtime, final RubyModule Java, final RubyClass JavaObject) { // TODO: Determine if a real allocator is needed here. Do people want to extend // JavaClass? Do we want them to do that? Can you Class.new(JavaClass)? Should you be able to? // NOTE: NOT_ALLOCATABLE_ALLOCATOR is probably OK here, since we don't intend for people to monkey with // this type and it can't be marshalled. Confirm. JRUBY-415 RubyClass JavaClass = Java.defineClassUnder("JavaClass", JavaObject, ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR); JavaClass.includeModule(runtime.getModule("Comparable")); JavaClass.defineAnnotatedMethods(JavaClass.class); JavaClass.getMetaClass().undefineMethod("new"); JavaClass.getMetaClass().undefineMethod("allocate"); return JavaClass; }
public void load(Ruby runtime, boolean wrap) throws IOException { RubyModule mJRubyUtil = runtime.getOrCreateModule("JRuby").defineModuleUnder("Util"); mJRubyUtil.defineAnnotatedMethods(JRubyUtilLibrary.class); // core class utils runtime.getString().defineAnnotatedMethods(StringUtils.class); }