org.jruby.Ruby.evalScriptlet()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(238)

本文整理了Java中org.jruby.Ruby.evalScriptlet方法的一些代码示例,展示了Ruby.evalScriptlet的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ruby.evalScriptlet方法的具体详情如下:
包路径:org.jruby.Ruby
类名称:Ruby
方法名:evalScriptlet

Ruby.evalScriptlet介绍

[英]Evaluates a script under the current scope (perhaps the top-level scope) and returns the result (generally the last value calculated). This version goes straight into the interpreter, bypassing compilation and runtime preparation typical to normal script runs.
[中]在当前作用域(可能是顶级作用域)下计算脚本,并返回结果(通常是最后计算的值)。这个版本直接进入解释器,绕过编译和运行时准备,这是正常脚本运行的典型情况。

代码示例

代码示例来源:origin: bazelbuild/bazel

public static IRubyObject validateStringEncoding(ThreadContext context, Descriptors.FieldDescriptor.Type type, IRubyObject value) {
  if (!(value instanceof RubyString))
    throw context.runtime.newTypeError("Invalid argument for string field.");
  switch(type) {
    case BYTES:
      value = ((RubyString)value).encode(context, context.runtime.evalScriptlet("Encoding::ASCII_8BIT"));
      break;
    case STRING:
      value = ((RubyString)value).encode(context, context.runtime.evalScriptlet("Encoding::UTF_8"));
      break;
    default:
      break;
  }
  value.setFrozen(true);
  return value;
}

代码示例来源:origin: org.jruby/jruby-complete

/**
 * Evaluate a script and return the last value in the script.
 * @param runtime to invoke the script under
 * @param script to be evaluated
 * @return the last value of the script
 */
public IRubyObject eval(Ruby runtime, String script) {
  return runtime.evalScriptlet(script);
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

/**
 * Evaluate a script and return the last value in the script.
 * @param runtime to invoke the script under
 * @param script to be evaluated
 * @return the last value of the script
 */
public IRubyObject eval(Ruby runtime, String script) {
  return runtime.evalScriptlet(script);
}

代码示例来源:origin: org.jruby.rack/jruby-rack

@Override
  public IRubyObject createApplicationObject(Ruby runtime) {
    runtime.evalScriptlet("load 'jruby/rack/boot/rails.rb'");
    runtime.evalScriptlet("JRuby::Rack::RailsBooter.load_environment");
    return createRackServletWrapper(runtime, "run JRuby::Rack::RailsBooter.to_app");
  }
}

代码示例来源:origin: org.asciidoctor/asciidoctor-java-integration

void inject(Map<String, Object> environmentVars) {
  
  Set<Entry<String, Object>> environmentVariablesAndValues = environmentVars.entrySet();
  
  for (Entry<String, Object> entry : environmentVariablesAndValues) {
    runtime.evalScriptlet(String.format("ENV['%s']=\"%s\"", entry.getKey(), entry.getValue()));
  }
  
}

代码示例来源:origin: org.asciidoctor/asciidoctor-java-integration

public void includeProcessor(
    Class<? extends IncludeProcessor> includeProcessor) {
  // this may change in future to external class to deal with dynamic
  // imports
  this.rubyRuntime.evalScriptlet("java_import "
      + includeProcessor.getName());
  this.asciidoctorModule.include_processor(includeProcessor
      .getSimpleName());
}

代码示例来源:origin: org.asciidoctor/asciidoctor-java-integration

public void preprocessor(Class<? extends Preprocessor> preprocessor) {
  // this may change in future to external class to deal with dynamic
  // imports
  this.rubyRuntime.evalScriptlet("java_import " + preprocessor.getName());
  this.asciidoctorModule.preprocessor(preprocessor.getSimpleName());
}

代码示例来源:origin: org.asciidoctor/asciidoctor-java-integration

public void inlineMacro(String blockName,
    Class<? extends InlineMacroProcessor> inlineMacroProcessor) {
  // this may change in future to external class to deal with dynamic
  // imports
  this.rubyRuntime.evalScriptlet("java_import "
      + inlineMacroProcessor.getName());
  this.asciidoctorModule.inline_macro(
      RubyUtils.toSymbol(rubyRuntime, blockName),
      inlineMacroProcessor.getSimpleName());
}

代码示例来源:origin: org.asciidoctor/asciidoctor-java-integration

public void blockMacro(String blockName,
    Class<? extends BlockMacroProcessor> blockMacroProcessor) {
  // this may change in future to external class to deal with dynamic
  // imports
  this.rubyRuntime.evalScriptlet("java_import "
      + blockMacroProcessor.getName());
  this.asciidoctorModule.block_macro(
      RubyUtils.toSymbol(rubyRuntime, blockName),
      blockMacroProcessor.getSimpleName());
}

代码示例来源:origin: asciidoctor/asciidoctorj

private JRubyAsciidoctor(final Ruby rubyRuntime) {
  this.rubyRuntime = rubyRuntime;
  InputStream inputStream = getClass().getResourceAsStream("asciidoctorclass.rb");
  final String script = IOUtils.readFull(inputStream);
  this.rubyRuntime.evalScriptlet(script);
  this.rubyGemsPreloader = new RubyGemsPreloader(this.rubyRuntime);
  this.logHandlers.add(new JULLogHandler());
}

代码示例来源:origin: org.asciidoctor/asciidoctorj

private JRubyAsciidoctor(final Ruby rubyRuntime) {
  this.rubyRuntime = rubyRuntime;
  InputStream inputStream = getClass().getResourceAsStream("asciidoctorclass.rb");
  final String script = IOUtils.readFull(inputStream);
  this.rubyRuntime.evalScriptlet(script);
  this.rubyGemsPreloader = new RubyGemsPreloader(this.rubyRuntime);
  this.logHandlers.add(new JULLogHandler());
}

代码示例来源:origin: org.asciidoctor/asciidoctorj

private void setTimingsMode(Asciidoctor asciidoctor, AsciidoctorCliOptions asciidoctorCliOptions, Options options) {
  if (asciidoctorCliOptions.isTimings()) {
    options.setOption("timings",
      JRubyRuntimeContext.get(asciidoctor).evalScriptlet("Asciidoctor::Timings.new"));
  }
}

代码示例来源:origin: asciidoctor/asciidoctorj

private void setTimingsMode(Asciidoctor asciidoctor, AsciidoctorCliOptions asciidoctorCliOptions, Options options) {
  if (asciidoctorCliOptions.isTimings()) {
    options.setOption("timings",
      JRubyRuntimeContext.get(asciidoctor).evalScriptlet("Asciidoctor::Timings.new"));
  }
}

代码示例来源:origin: org.jruby.rack/jruby-rack

public IRubyObject createApplicationObject(final Ruby runtime) {
  if (rackupScript == null) {
    rackContext.log(RackLogger.WARN, "no rackup script found - starting empty Rack application!");
    rackupScript = "";
  }
  checkAndSetRackVersion(runtime);
  runtime.evalScriptlet("load 'jruby/rack/boot/rack.rb'");
  return createRackServletWrapper(runtime, rackupScript, rackupLocation);
}

代码示例来源:origin: asciidoctor/asciidoctorj

@Test
public void should_not_have_gempath_in_ruby_env_when_created_with_null_gempath() {
  // Given: Our environment is polluted (Cannot set these env vars here, so just check that gradle has set them correctly)
  assertThat(System.getenv("GEM_PATH"), notNullValue());
  assertThat(System.getenv("GEM_HOME"), notNullValue());
  // When: A new Asciidoctor instance is created passing in a null GEM_PATH
  Asciidoctor asciidoctor = Asciidoctor.Factory.create((String) null);
  // Then: The org.jruby.JRuby instance does not see this variable
  Ruby rubyRuntime = JRubyRuntimeContext.get(asciidoctor);
  assertThat(rubyRuntime.evalScriptlet("ENV['GEM_PATH']"), is(rubyRuntime.getNil()));
  assertThat(rubyRuntime.evalScriptlet("ENV['GEM_HOME']"), is(rubyRuntime.getNil()));
}

代码示例来源:origin: asciidoctor/asciidoctorj

@Test
public void should_have_gempath_in_ruby_env_when_created_with_default_create() {
  // Given: Our environment is polluted (Cannot set these env vars here, so just check that gradle has set them correctly)
  assertThat(System.getenv("GEM_PATH"), notNullValue());
  assertThat(System.getenv("GEM_HOME"), notNullValue());
  // When: A new Asciidoctor instance is created passing in no GEM_PATH
  Asciidoctor asciidoctor = Asciidoctor.Factory.create();
  // Then: The org.jruby.JRuby instance sees this variable
  Ruby rubyRuntime = JRubyRuntimeContext.get(asciidoctor);
  assertThat(rubyRuntime.evalScriptlet("ENV['GEM_PATH']"), is(rubyRuntime.getNil()));
  assertThat(rubyRuntime.evalScriptlet("ENV['GEM_HOME']"), is(rubyRuntime.getNil()));
}

代码示例来源:origin: asciidoctor/asciidoctorj

@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));
}

代码示例来源:origin: asciidoctor/asciidoctorj

@Test
public void not_erubis_gem_should_be_preloaded() {
  Map<String, Object> options = OptionsBuilder.options().eruby("erb").asMap();
  ((JRubyAsciidoctor) asciidoctor).rubyGemsPreloader.preloadRequiredLibraries(options);
  RubyBoolean evalScriptlet = (RubyBoolean) ((JRubyAsciidoctor) asciidoctor).rubyRuntime.evalScriptlet("require 'erubis'");
  assertThat(evalScriptlet.isTrue(), is(true));
}

代码示例来源:origin: asciidoctor/asciidoctorj

@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));
}

代码示例来源:origin: asciidoctor/asciidoctorj

@Test
public void not_coderay_gem_should_not_be_preloaded() {
  Map<String, Object> options = OptionsBuilder.options()
      .attributes(AttributesBuilder.attributes().sourceHighlighter("pygments").get()).asMap();
  ((JRubyAsciidoctor) asciidoctor).rubyGemsPreloader.preloadRequiredLibraries(options);
  RubyBoolean evalScriptlet = (RubyBoolean) ((JRubyAsciidoctor) asciidoctor).rubyRuntime.evalScriptlet("require 'coderay'");
  assertThat(evalScriptlet.isTrue(), is(true));
}

相关文章

Ruby类方法