Class: RVM::Safety

Inherits:
Object
  • Object
show all
Defined in:
lib/rvm.rb

Overview

This class is designed to allow execting code more safely

It allows to limit executin in multiple ways to prevent all sorty of runaway code.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Safety

Returns a new instance of Safety.



25
26
27
# File 'lib/rvm.rb', line 25

def initialize options = {}
  @timeout = options[:timeout]
end

Instance Attribute Details

#timeoutObject

Returns the value of attribute timeout.



24
25
26
# File 'lib/rvm.rb', line 24

def timeout
  @timeout
end

Instance Method Details

#execute(code, env) ⇒ Object

Executes the code with the former set security measures.

Exceptions are thrown according to the problem



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rvm.rb', line 40

def execute code, env
  res = nil
  if @timeout
    Timeout::timeout(@timeout) do
      res = code.execute(env)
    end
  else
    res = code.execute(env)
  end
  res
end