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

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

本文整理了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

  1. public static IRubyObject validateStringEncoding(ThreadContext context, Descriptors.FieldDescriptor.Type type, IRubyObject value) {
  2. if (!(value instanceof RubyString))
  3. throw context.runtime.newTypeError("Invalid argument for string field.");
  4. switch(type) {
  5. case BYTES:
  6. value = ((RubyString)value).encode(context, context.runtime.evalScriptlet("Encoding::ASCII_8BIT"));
  7. break;
  8. case STRING:
  9. value = ((RubyString)value).encode(context, context.runtime.evalScriptlet("Encoding::UTF_8"));
  10. break;
  11. default:
  12. break;
  13. }
  14. value.setFrozen(true);
  15. return value;
  16. }

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

  1. /**
  2. * Evaluate a script and return the last value in the script.
  3. * @param runtime to invoke the script under
  4. * @param script to be evaluated
  5. * @return the last value of the script
  6. */
  7. public IRubyObject eval(Ruby runtime, String script) {
  8. return runtime.evalScriptlet(script);
  9. }

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

  1. /**
  2. * Evaluate a script and return the last value in the script.
  3. * @param runtime to invoke the script under
  4. * @param script to be evaluated
  5. * @return the last value of the script
  6. */
  7. public IRubyObject eval(Ruby runtime, String script) {
  8. return runtime.evalScriptlet(script);
  9. }

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

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

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

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

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

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

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

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

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

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

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

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

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

  1. private JRubyAsciidoctor(final Ruby rubyRuntime) {
  2. this.rubyRuntime = rubyRuntime;
  3. InputStream inputStream = getClass().getResourceAsStream("asciidoctorclass.rb");
  4. final String script = IOUtils.readFull(inputStream);
  5. this.rubyRuntime.evalScriptlet(script);
  6. this.rubyGemsPreloader = new RubyGemsPreloader(this.rubyRuntime);
  7. this.logHandlers.add(new JULLogHandler());
  8. }

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

  1. private JRubyAsciidoctor(final Ruby rubyRuntime) {
  2. this.rubyRuntime = rubyRuntime;
  3. InputStream inputStream = getClass().getResourceAsStream("asciidoctorclass.rb");
  4. final String script = IOUtils.readFull(inputStream);
  5. this.rubyRuntime.evalScriptlet(script);
  6. this.rubyGemsPreloader = new RubyGemsPreloader(this.rubyRuntime);
  7. this.logHandlers.add(new JULLogHandler());
  8. }

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

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

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

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

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

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

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

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

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

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

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

  1. @Test
  2. public void erubis_gem_should_be_preloaded() {
  3. Map<String, Object> options = OptionsBuilder.options().eruby("erubis").asMap();
  4. ((JRubyAsciidoctor) asciidoctor).rubyGemsPreloader.preloadRequiredLibraries(options);
  5. RubyBoolean evalScriptlet = (RubyBoolean) ((JRubyAsciidoctor) asciidoctor).rubyRuntime.evalScriptlet("require 'erubis'");
  6. assertThat(evalScriptlet.isFalse(), is(true));
  7. }

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

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

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

  1. @Test
  2. public void data_uri_gem_should_be_preloaded() {
  3. Map<String, Object> options = OptionsBuilder.options()
  4. .attributes(AttributesBuilder.attributes().dataUri(true).get()).asMap();
  5. ((JRubyAsciidoctor) asciidoctor).rubyGemsPreloader.preloadRequiredLibraries(options);
  6. RubyBoolean evalScriptlet = (RubyBoolean) ((JRubyAsciidoctor) asciidoctor).rubyRuntime.evalScriptlet("require 'base64'");
  7. assertThat(evalScriptlet.isFalse(), is(true));
  8. }

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

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

相关文章

Ruby类方法