@Override public Object toJava(Class target) { if (target.isAssignableFrom(Boolean.class) || target.equals(boolean.class)) { if (isFalse()) return Boolean.FALSE; return Boolean.TRUE; } else { return super.toJava(target); } } }
@Override public Object toJava(Class target) { if (target.isAssignableFrom(Boolean.class) || target.equals(boolean.class)) { if (isFalse()) return Boolean.FALSE; return Boolean.TRUE; } else { return super.toJava(target); } } }
/** cmp_between * */ @JRubyMethod(name = "between?", required = 2) public static RubyBoolean between_p(ThreadContext context, IRubyObject recv, IRubyObject first, IRubyObject second) { return context.runtime.newBoolean(op_lt(context, recv, first).isFalse() && op_gt(context, recv, second).isFalse()); } }
/** cmp_between * */ @JRubyMethod(name = "between?", required = 2) public static RubyBoolean between_p(ThreadContext context, IRubyObject recv, IRubyObject first, IRubyObject second) { return context.runtime.newBoolean(op_lt(context, recv, first).isFalse() && op_gt(context, recv, second).isFalse()); }
/** cmp_between * */ @JRubyMethod(name = "between?", required = 2) public static RubyBoolean between_p(ThreadContext context, IRubyObject recv, IRubyObject first, IRubyObject second) { return context.runtime.newBoolean(op_lt(context, recv, first).isFalse() && op_gt(context, recv, second).isFalse()); }
/** cmp_between * */ @JRubyMethod(name = "between?", required = 2) public static RubyBoolean between_p(ThreadContext context, IRubyObject recv, IRubyObject first, IRubyObject second) { return context.runtime.newBoolean(op_lt(context, recv, first).isFalse() && op_gt(context, recv, second).isFalse()); } }
public static RubyArray unpack_sockaddr_in(ThreadContext context, IRubyObject addr) { final Ruby runtime = context.runtime; if (addr instanceof Addrinfo) { Addrinfo addrinfo = (Addrinfo)addr; if (((RubyBoolean)addrinfo.ip_p(context)).isFalse()) { throw runtime.newArgumentError("not an AF_INET/AF_INET6 sockaddr"); } return RubyArray.newArray(runtime, addrinfo.ip_port(context), addrinfo.ip_address(context)); } ByteList val = addr.convertToString().getByteList(); return unpack_sockaddr_in(context, val); }
public static RubyArray unpack_sockaddr_in(ThreadContext context, IRubyObject addr) { final Ruby runtime = context.runtime; if (addr instanceof Addrinfo) { Addrinfo addrinfo = (Addrinfo)addr; if (((RubyBoolean)addrinfo.ip_p(context)).isFalse()) { throw runtime.newArgumentError("not an AF_INET/AF_INET6 sockaddr"); } return RubyArray.newArray(runtime, addrinfo.ip_port(context), addrinfo.ip_address(context)); } ByteList val = addr.convertToString().getByteList(); return unpack_sockaddr_in(context, val); }
public IRubyObject getRange(ThreadContext context, IRubyObject arg0) { int length = Array.getLength(getObject()); if (arg0 instanceof RubyRange) { RubyRange range = (RubyRange)arg0; if (range.first() instanceof RubyFixnum && range.last() instanceof RubyFixnum) { int first = (int)((RubyFixnum)range.first()).getLongValue(); int last = (int)((RubyFixnum)range.last()).getLongValue(); first = first >= 0 ? first : length + first; last = last >= 0 ? last : length + last; int newLength = last - first; if (range.exclude_end_p().isFalse()) newLength += 1; if (newLength <= 0) { return ArrayUtils.emptyJavaArrayDirect(context, getObject().getClass().getComponentType()); } return ArrayUtils.javaArraySubarrayDirect(context, getObject(), first, newLength); } else { throw context.runtime.newTypeError("only Fixnum ranges supported"); } } else { throw context.runtime.newTypeError(arg0, context.runtime.getRange()); } }
@Test public void template_dir_should_preload_tilt() { Map<String, Object> options = OptionsBuilder.options().templateDir(new File(".")).asMap(); ((JRubyAsciidoctor) asciidoctor).rubyGemsPreloader.preloadRequiredLibraries(options); RubyBoolean evalScriptlet = (RubyBoolean) ((JRubyAsciidoctor) asciidoctor).rubyRuntime.evalScriptlet("require 'tilt'"); assertThat(evalScriptlet.isFalse(), is(true)); }
public IRubyObject getRange(ThreadContext context, IRubyObject arg0) { int length = Array.getLength(getObject()); if (arg0 instanceof RubyRange) { RubyRange range = (RubyRange)arg0; if (range.first() instanceof RubyFixnum && range.last() instanceof RubyFixnum) { int first = (int)((RubyFixnum)range.first()).getLongValue(); int last = (int)((RubyFixnum)range.last()).getLongValue(); first = first >= 0 ? first : length + first; last = last >= 0 ? last : length + last; int newLength = last - first; if (range.exclude_end_p().isFalse()) newLength += 1; if (newLength <= 0) { return ArrayUtils.emptyJavaArrayDirect(context, getObject().getClass().getComponentType()); } return ArrayUtils.javaArraySubarrayDirect(context, getObject(), first, newLength); } else { throw context.runtime.newTypeError("only Fixnum ranges supported"); } } else { throw context.runtime.newTypeError(arg0, context.runtime.getRange()); } }
@Test public void erubis_gem_should_be_preloaded() { Map<String, Object> options = OptionsBuilder.options().eruby("erubis").asMap(); ((JRubyAsciidoctor) asciidoctor).rubyGemsPreloader.preloadRequiredLibraries(options); RubyBoolean evalScriptlet = (RubyBoolean) ((JRubyAsciidoctor) asciidoctor).rubyRuntime.evalScriptlet("require 'erubis'"); assertThat(evalScriptlet.isFalse(), is(true)); }
@Deprecated protected LoadServiceResource tryResourceFromHome(SearchState state, String baseName, SuffixType suffixType) throws RaiseException { LoadServiceResource foundResource = null; RubyHash env = (RubyHash) runtime.getObject().getConstant("ENV"); RubyString env_home = runtime.newString("HOME"); if (env.has_key_p(env_home).isFalse()) { return null; } String home = env.op_aref(runtime.getCurrentContext(), env_home).toString(); String path = baseName.substring(2); for (String suffix : suffixType.getSuffixes()) { String namePlusSuffix = path + suffix; // check home directory; if file exists, retrieve URL and return resource try { JRubyFile file = JRubyFile.create(home, RubyFile.expandUserPath(runtime.getCurrentContext(), namePlusSuffix)); debugLogTry("resourceFromHome", file.toString()); if (file.isFile() && file.isAbsolute() && file.canRead()) { boolean absolute = true; state.setLoadName(file.getPath()); foundResource = new LoadServiceResource(file, state.loadName, absolute); debugLogFound(foundResource); break; } } catch (IllegalArgumentException illArgEx) { } catch (SecurityException secEx) { } } return foundResource; }
public static IRubyObject unpack_sockaddr_un(ThreadContext context, IRubyObject addr) { final Ruby runtime = context.runtime; if (addr instanceof Addrinfo) { Addrinfo addrinfo = (Addrinfo)addr; if (((RubyBoolean)addrinfo.unix_p(context)).isFalse()) { throw runtime.newArgumentError("not an AF_UNIX sockaddr"); } return addrinfo.unix_path(context); } ByteList val = addr.convertToString().getByteList(); AddressFamily af = getAddressFamilyFromSockaddr(runtime, val); if (af != AddressFamily.AF_UNIX) { throw runtime.newArgumentError("not an AF_UNIX sockaddr"); } String filename = pathFromSockaddr_un(context, val.bytes()); return context.runtime.newString(filename); }
public static IRubyObject unpack_sockaddr_un(ThreadContext context, IRubyObject addr) { final Ruby runtime = context.runtime; if (addr instanceof Addrinfo) { Addrinfo addrinfo = (Addrinfo)addr; if (((RubyBoolean)addrinfo.unix_p(context)).isFalse()) { throw runtime.newArgumentError("not an AF_UNIX sockaddr"); } return addrinfo.unix_path(context); } ByteList val = addr.convertToString().getByteList(); AddressFamily af = getAddressFamilyFromSockaddr(runtime, val); if (af != AddressFamily.AF_UNIX) { throw runtime.newArgumentError("not an AF_UNIX sockaddr"); } String filename = pathFromSockaddr_un(context, val.bytes()); return context.runtime.newString(filename); }
@Deprecated protected LoadServiceResource tryResourceFromHome(SearchState state, String baseName, SuffixType suffixType) throws RaiseException { LoadServiceResource foundResource = null; RubyHash env = (RubyHash) runtime.getObject().getConstant("ENV"); RubyString env_home = runtime.newString("HOME"); if (env.has_key_p(env_home).isFalse()) { return null; } String home = env.op_aref(runtime.getCurrentContext(), env_home).toString(); String path = baseName.substring(2); for (String suffix : suffixType.getSuffixes()) { String namePlusSuffix = path + suffix; // check home directory; if file exists, retrieve URL and return resource try { JRubyFile file = JRubyFile.create(home, RubyFile.expandUserPath(runtime.getCurrentContext(), namePlusSuffix)); debugLogTry("resourceFromHome", file.toString()); if (file.isFile() && file.isAbsolute() && file.canRead()) { boolean absolute = true; state.setLoadName(file.getPath()); foundResource = new LoadServiceResource(file, state.loadName, absolute); debugLogFound(foundResource); break; } } catch (IllegalArgumentException illArgEx) { } catch (SecurityException secEx) { } } return foundResource; }
protected LoadServiceResource tryResourceFromHome(SearchState state, String baseName, SuffixType suffixType) throws RaiseException { LoadServiceResource foundResource = null; RubyHash env = (RubyHash) runtime.getObject().getConstant("ENV"); RubyString env_home = runtime.newString("HOME"); if (env.has_key_p(env_home).isFalse()) { return null; } String home = env.op_aref(runtime.getCurrentContext(), env_home).toString(); String path = baseName.substring(2); for (String suffix : suffixType.getSuffixes()) { String namePlusSuffix = path + suffix; // check home directory; if file exists, retrieve URL and return resource try { JRubyFile file = JRubyFile.create(home, RubyFile.expandUserPath(runtime.getCurrentContext(), namePlusSuffix)); debugLogTry("resourceFromHome", file.toString()); if (file.isFile() && file.isAbsolute() && file.canRead()) { boolean absolute = true; state.loadName = file.getPath(); foundResource = new LoadServiceResource(file, state.loadName, absolute); debugLogFound(foundResource); break; } } catch (IllegalArgumentException illArgEx) { } catch (SecurityException secEx) { } } return foundResource; }
protected LoadServiceResource tryResourceFromHome(SearchState state, String baseName, SuffixType suffixType) throws RaiseException { LoadServiceResource foundResource = null; RubyHash env = (RubyHash) runtime.getObject().getConstant("ENV"); RubyString env_home = runtime.newString("HOME"); if (env.has_key_p(env_home).isFalse()) { return null; } String home = env.op_aref(runtime.getCurrentContext(), env_home).toString(); String path = baseName.substring(2); for (String suffix : suffixType.getSuffixes()) { String namePlusSuffix = path + suffix; // check home directory; if file exists, retrieve URL and return resource try { JRubyFile file = JRubyFile.create(home, RubyFile.expandUserPath(runtime.getCurrentContext(), namePlusSuffix)); debugLogTry("resourceFromHome", file.toString()); if (file.isFile() && file.isAbsolute() && file.canRead()) { boolean absolute = true; state.loadName = file.getPath(); foundResource = new LoadServiceResource(file, state.loadName, absolute); debugLogFound(foundResource); break; } } catch (IllegalArgumentException illArgEx) { } catch (SecurityException secEx) { } } return foundResource; }
@Test public void coderay_gem_should_be_preloaded() { Map<String, Object> options = OptionsBuilder.options() .attributes(AttributesBuilder.attributes().sourceHighlighter("coderay").get()).asMap(); ((JRubyAsciidoctor) asciidoctor).rubyGemsPreloader.preloadRequiredLibraries(options); RubyBoolean evalScriptlet = (RubyBoolean) ((JRubyAsciidoctor) asciidoctor).rubyRuntime.evalScriptlet("require 'coderay'"); assertThat(evalScriptlet.isFalse(), is(true)); }
@Test public void data_uri_gem_should_be_preloaded() { Map<String, Object> options = OptionsBuilder.options() .attributes(AttributesBuilder.attributes().dataUri(true).get()).asMap(); ((JRubyAsciidoctor) asciidoctor).rubyGemsPreloader.preloadRequiredLibraries(options); RubyBoolean evalScriptlet = (RubyBoolean) ((JRubyAsciidoctor) asciidoctor).rubyRuntime.evalScriptlet("require 'base64'"); assertThat(evalScriptlet.isFalse(), is(true)); }