Class: RVM::Safety
- Inherits:
-
Object
- Object
- RVM::Safety
- 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
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#execute(code, env) ⇒ Object
Executes the code with the former set security measures.
-
#initialize(options = {}) ⇒ Safety
constructor
A new instance of Safety.
Constructor Details
#initialize(options = {}) ⇒ Safety
Returns a new instance of Safety.
25 26 27 |
# File 'lib/rvm.rb', line 25 def initialize = {} @timeout = [:timeout] end |
Instance Attribute Details
#timeout ⇒ Object
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 |