Class: Midori::Sandbox
- Inherits:
-
Object
- Object
- Midori::Sandbox
- Defined in:
- lib/midori/sandbox.rb
Overview
Sandbox for global error capture
Class Method Summary collapse
-
.add_rule(class_name, block) ⇒ nil
Add a rule to Sandbox.
-
.capture(error) ⇒ nil
Detect what to run with given error.
-
.run(clean_room, function, *args) ⇒ nil
Run sandbox inside given clean room.
Class Method Details
.add_rule(class_name, block) ⇒ nil
Add a rule to Sandbox
15 16 17 18 |
# File 'lib/midori/sandbox.rb', line 15 def add_rule(class_name, block) @handlers[class_name] = block nil end |
.capture(error) ⇒ nil
Detect what to run with given error
23 24 25 26 27 28 29 |
# File 'lib/midori/sandbox.rb', line 23 def capture(error) if @handlers[error.class].nil? @handlers[Midori::Exception::InternalError].call(error) else @handlers[error.class].call(error) end end |
.run(clean_room, function, *args) ⇒ nil
Run sandbox inside given clean room
35 36 37 38 39 40 41 |
# File 'lib/midori/sandbox.rb', line 35 def run(clean_room, function, *args) begin function.to_lambda(clean_room).call(*args) rescue StandardError => e capture(e) end end |