Module: Mulligan::Condition
- Included in:
- Exception
- Defined in:
- lib/mulligan/condition.rb
Instance Method Summary collapse
-
#has_recovery?(id) ⇒ Boolean
Checks for the presence of a recovery.
-
#recover(id, *params) ⇒ Object
Executes the recovery.
-
#recovery_identifiers ⇒ Enumerable
Retrieves all the identifiers for available recoveries.
-
#recovery_options(id) ⇒ Hash
Retrieves the options specified when a recovery was made.
- #set_recovery(id, options = {}, &block) ⇒ Object
Instance Method Details
#has_recovery?(id) ⇒ Boolean
Checks for the presence of a recovery
36 37 38 |
# File 'lib/mulligan/condition.rb', line 36 def has_recovery?(id) recoveries.has_key?(id.to_sym) end |
#recover(id, *params) ⇒ Object
Executes the recovery. This actually places the stack back to just after the ‘#raise` that brought us to this `rescue` clause. Then the recovery block is executed and the program continues on.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/mulligan/condition.rb', line 64 def recover(id, *params) raise Mulligan::UnsupportedException unless Mulligan.supported? Thread.current[:__last_recovery__] = nil raise ControlException unless has_recovery?(id.to_sym) data = recoveries[id.to_sym] if data[:continuation].nil? $stderr.puts "Cannot invoke restart #{id}. Must first raise this exception: '#{self.inspect}'" return end Thread.current[:__last_recovery__] = id data[:continuation].call(*data[:block].call(*params)) true end |
#recovery_identifiers ⇒ Enumerable
Retrieves all the identifiers for available recoveries
52 53 54 |
# File 'lib/mulligan/condition.rb', line 52 def recovery_identifiers recoveries.keys end |
#recovery_options(id) ⇒ Hash
Retrieves the options specified when a recovery was made
44 45 46 47 |
# File 'lib/mulligan/condition.rb', line 44 def (id) return nil unless has_recovery?(id.to_sym) recoveries[id.to_sym].dup.reject{|k,v| [:block, :continuation].include? k} end |
#set_recovery(id, options = {}, &block) ⇒ Object
21 22 23 24 25 |
# File 'lib/mulligan/condition.rb', line 21 def set_recovery(id, ={}, &block) return if block.nil? recoveries[id.to_sym] = .merge(:block => block) nil end |