Module: Cond::DSL
- Included in:
- Cond
- Defined in:
- lib/cond/dsl_definition.rb
Instance Method Summary collapse
-
#again(*args) ⇒ Object
Run the handling or restartable block again.
-
#handle(arg, message = "", &block) ⇒ Object
Define a handler.
-
#handling(&block) ⇒ Object
Begin a handling block.
-
#invoke_restart(name, *args, &block) ⇒ Object
Call a restart from a handler; optionally pass it some arguments.
-
#leave(*args) ⇒ Object
Leave the current handling or restartable block, optionally providing a value for the block.
-
#restart(arg, message = "", &block) ⇒ Object
Define a restart.
-
#restartable(&block) ⇒ Object
Begin a restartable block.
Instance Method Details
#again(*args) ⇒ Object
Run the handling or restartable block again.
Optionally pass arguments which are given to the block.
59 60 61 62 |
# File 'lib/cond/dsl_definition.rb', line 59 def again(*args) Cond.check_context(:again) Cond.code_section_stack.last.again(*args) end |
#handle(arg, message = "", &block) ⇒ Object
Define a handler.
The exception instance is passed to the block.
25 26 27 28 |
# File 'lib/cond/dsl_definition.rb', line 25 def handle(arg, = "", &block) Cond.check_context(:handle) Cond.code_section_stack.last.handle(arg, , &block) end |
#handling(&block) ⇒ Object
Begin a handling block. Inside this block, a matching handler gets called when raise gets called.
8 9 10 |
# File 'lib/cond/dsl_definition.rb', line 8 def handling(&block) Cond.run_code_section(HandlingSection, &block) end |
#invoke_restart(name, *args, &block) ⇒ Object
Call a restart from a handler; optionally pass it some arguments.
67 68 69 70 71 72 |
# File 'lib/cond/dsl_definition.rb', line 67 def invoke_restart(name, *args, &block) Cond.available_restarts.fetch(name) { raise NoRestartError, "Did not find `#{name.inspect}' in available restarts" }.call(*args, &block) end |
#leave(*args) ⇒ Object
Leave the current handling or restartable block, optionally providing a value for the block.
The semantics are the same as ‘return’. When given multiple arguments, it returns an array. When given one argument, it returns only that argument (not an array).
49 50 51 52 |
# File 'lib/cond/dsl_definition.rb', line 49 def leave(*args) Cond.check_context(:leave) Cond.code_section_stack.last.leave(*args) end |
#restart(arg, message = "", &block) ⇒ Object
Define a restart.
When a handler calls invoke_restart, it may pass additional arguments which are in turn passed to &block.
36 37 38 39 |
# File 'lib/cond/dsl_definition.rb', line 36 def restart(arg, = "", &block) Cond.check_context(:restart) Cond.code_section_stack.last.restart(arg, , &block) end |
#restartable(&block) ⇒ Object
Begin a restartable block. A handler may transfer control to one of the restarts in this block.
16 17 18 |
# File 'lib/cond/dsl_definition.rb', line 16 def restartable(&block) Cond.run_code_section(RestartableSection, &block) end |