Module: Sensu::Server::Sandbox

Defined in:
lib/sensu/server/sandbox.rb

Class Method Summary collapse

Class Method Details

.eval(expression, value = nil) ⇒ Object

Evaluate a Ruby expression within the context of a simple “sandbox”, a Proc in a module method. Use the Ruby ‘$SAFE` level of 4 when the version of Ruby is less than 2.1.0. A single value is provided to the “sandbox”.

Parameters:

  • expression (String)

    to be evaluated.

  • value (Object) (defaults to: nil)

    to provide the “sandbox” with.

Returns:

  • (Object)


12
13
14
15
16
17
18
# File 'lib/sensu/server/sandbox.rb', line 12

def self.eval(expression, value=nil)
  result = Proc.new do
    $SAFE = (RUBY_VERSION < "2.1.0" ? 4 : 3)
    Kernel.eval(expression)
  end
  result.call
end