Class: ScriptCore::Engine
Instance Attribute Summary collapse
-
#instruction_quota ⇒ Object
Returns the value of attribute instruction_quota.
-
#instruction_quota_start ⇒ Object
Returns the value of attribute instruction_quota_start.
-
#instructions ⇒ Object
Returns the value of attribute instructions.
-
#memory_quota ⇒ Object
Returns the value of attribute memory_quota.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #eval(sources, input: nil, instruction_quota_start: nil, environment_variables: {}) ⇒ Object
-
#initialize(bin_path = ScriptCore::DEFAULT_BIN_PATH, executable_name: "enterprise_script_service", instructions_name: "enterprise_script_service.mrb") ⇒ Engine
constructor
A new instance of Engine.
Constructor Details
#initialize(bin_path = ScriptCore::DEFAULT_BIN_PATH, executable_name: "enterprise_script_service", instructions_name: "enterprise_script_service.mrb") ⇒ Engine
Returns a new instance of Engine.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/script_core/engine.rb', line 7 def initialize(bin_path = ScriptCore::DEFAULT_BIN_PATH, executable_name: "enterprise_script_service", instructions_name: "enterprise_script_service.mrb") raise Errno::ENOENT, "No such directory - #{bin_path}" unless File.directory?(bin_path) @bin_path = bin_path @executable = ScriptCore::Executable.new(@bin_path.join(executable_name)) @timeout = 1 @instruction_quota = 100_000 @instruction_quota_start = 0 @memory_quota = 8 << 20 preload_instructions_path = @bin_path.join(instructions_name) @instructions = File.exist?(preload_instructions_path) ? File.binread(preload_instructions_path) : nil end |
Instance Attribute Details
#instruction_quota ⇒ Object
Returns the value of attribute instruction_quota.
5 6 7 |
# File 'lib/script_core/engine.rb', line 5 def instruction_quota @instruction_quota end |
#instruction_quota_start ⇒ Object
Returns the value of attribute instruction_quota_start.
5 6 7 |
# File 'lib/script_core/engine.rb', line 5 def instruction_quota_start @instruction_quota_start end |
#instructions ⇒ Object
Returns the value of attribute instructions.
5 6 7 |
# File 'lib/script_core/engine.rb', line 5 def instructions @instructions end |
#memory_quota ⇒ Object
Returns the value of attribute memory_quota.
5 6 7 |
# File 'lib/script_core/engine.rb', line 5 def memory_quota @memory_quota end |
#timeout ⇒ Object
Returns the value of attribute timeout.
5 6 7 |
# File 'lib/script_core/engine.rb', line 5 def timeout @timeout end |
Instance Method Details
#eval(sources, input: nil, instruction_quota_start: nil, environment_variables: {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/script_core/engine.rb', line 24 def eval(sources, input: nil, instruction_quota_start: nil, environment_variables: {}) @executable.run( input: input || {}, sources: sources, instructions: @instructions, timeout: @timeout, instruction_quota: @instruction_quota, instruction_quota_start: instruction_quota_start || @instruction_quota_start, memory_quota: @memory_quota, environment_variables: environment_variables ) end |