Module: RescueFromError
- Extended by:
- RescueFromError
- Included in:
- RescueFromError
- Defined in:
- lib/clean-annotations/rescue_from.rb
Instance Method Summary collapse
Instance Method Details
#included(base) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/clean-annotations/rescue_from.rb', line 6 def included base def base.rescue_from what, &block raise ArgumemtError.new('Unsupported') if what.is_a?(Symbol) && what != :all key = [self, what].join('-') RESCUES[key] = block end end |
#resolve_rescue_from ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/clean-annotations/rescue_from.rb', line 15 def resolve_rescue_from begin yield rescue => error for klass in self.class.ancestors key = [klass, error.class].join('-') if block = RESCUES[key] return instance_exec(error, &block) end end for klass in self.class.ancestors key = [klass, :all].join('-') if block = RESCUES[key] return instance_exec(error, &block) end end end end |