module RubyBox::Execution

Public Instance Methods

maximum_execution_time() click to toggle source
# File lib/ruby_box/execution.rb, line 11
def maximum_execution_time
  @maximum_execution_time ||= begin
    if superclass.respond_to?(:maximum_execution_time)
      superclass.maximum_execution_time
    else
      nil
    end
  end
end
maximum_execution_time_ms() click to toggle source
# File lib/ruby_box/execution.rb, line 44
def maximum_execution_time_ms
  maximum_execution_time * 1000 if maximum_execution_time
end
snapshot() click to toggle source
# File lib/ruby_box/execution.rb, line 21
def snapshot
  @snapshot ||= begin
    MiniRacer::Snapshot.new snapshot_source
  end
rescue MiniRacer::SnapshotError
  raise ExecutionError, "The base snapshot for `#{name}` could not be created."
end
snapshot_source() click to toggle source
# File lib/ruby_box/execution.rb, line 31
def snapshot_source
  raise NotImplementedError
end
times_out_in(seconds) click to toggle source
# File lib/ruby_box/execution.rb, line 35
def times_out_in(seconds)
  @maximum_execution_time = seconds
end

Private Instance Methods

context() click to toggle source
# File lib/ruby_box/execution.rb, line 50
def context
  @context ||= MiniRacer::Context.new(snapshot: self.class.snapshot, timeout: maximum_execution_time_ms)
end
eval_compiled_source(source) click to toggle source
# File lib/ruby_box/execution.rb, line 54
def eval_compiled_source(source)
  context.eval source
rescue MiniRacer::RuntimeError => error
  raise RuntimeError, error.message
rescue MiniRacer::ScriptTerminatedError => error
  raise TimeoutError, error.message
end