Class: Sandrbox::Value
- Inherits:
-
Object
- Object
- Sandrbox::Value
- Defined in:
- lib/sandrbox/value.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#line ⇒ Object
Returns the value of attribute line.
-
#line_no ⇒ Object
Returns the value of attribute line_no.
-
#result ⇒ Object
Returns the value of attribute result.
-
#time ⇒ Object
Returns the value of attribute time.
-
#unbound_constants ⇒ Object
Returns the value of attribute unbound_constants.
-
#unbound_methods ⇒ Object
Returns the value of attribute unbound_methods.
Instance Method Summary collapse
- #evaluate ⇒ Object
-
#initialize(line, line_no) ⇒ Value
constructor
A new instance of Value.
- #to_s ⇒ Object
Constructor Details
#initialize(line, line_no) ⇒ Value
Returns a new instance of Value.
5 6 7 8 9 10 11 |
# File 'lib/sandrbox/value.rb', line 5 def initialize(line, line_no) self.unbound_methods = [] self.unbound_constants = [] self.line = line self.line_no = line_no evaluate end |
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
3 4 5 |
# File 'lib/sandrbox/value.rb', line 3 def error @error end |
#line ⇒ Object
Returns the value of attribute line.
3 4 5 |
# File 'lib/sandrbox/value.rb', line 3 def line @line end |
#line_no ⇒ Object
Returns the value of attribute line_no.
3 4 5 |
# File 'lib/sandrbox/value.rb', line 3 def line_no @line_no end |
#result ⇒ Object
Returns the value of attribute result.
3 4 5 |
# File 'lib/sandrbox/value.rb', line 3 def result @result end |
#time ⇒ Object
Returns the value of attribute time.
3 4 5 |
# File 'lib/sandrbox/value.rb', line 3 def time @time end |
#unbound_constants ⇒ Object
Returns the value of attribute unbound_constants.
3 4 5 |
# File 'lib/sandrbox/value.rb', line 3 def unbound_constants @unbound_constants end |
#unbound_methods ⇒ Object
Returns the value of attribute unbound_methods.
3 4 5 |
# File 'lib/sandrbox/value.rb', line 3 def unbound_methods @unbound_methods end |
Instance Method Details
#evaluate ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sandrbox/value.rb', line 13 def evaluate t = Thread.new do $SAFE = 2 begin Timeout::timeout(0.5) do Sandrbox.config.bad_methods.each {|meth| remove_method(meth.first, meth.last)} Sandrbox.config.bad_constants.each {|const| remove_constant(const)} self.result = eval(line, TOPLEVEL_BINDING, "sandrbox", line_no) end rescue Exception => e self.result = "#{e.class}: #{e.to_s}" self.error = true ensure restore_constants restore_methods end end timeout = t.join(3) if timeout.nil? self.result = "SandrboxError: execution expired" self.error = true end self end |
#to_s ⇒ Object
40 41 42 |
# File 'lib/sandrbox/value.rb', line 40 def to_s self.result end |