Class: Braai::Handlers::Base
- Inherits:
-
Object
- Object
- Braai::Handlers::Base
- Defined in:
- lib/braai/handlers/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#matches ⇒ Object
Returns the value of attribute matches.
-
#template ⇒ Object
Returns the value of attribute template.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(template, key, matches) ⇒ Base
constructor
A new instance of Base.
-
#perform ⇒ Object
override this method in your own handlers.
- #rescue_from_error(e) ⇒ Object
- #safe_perform ⇒ Object
Constructor Details
#initialize(template, key, matches) ⇒ Base
Returns a new instance of Base.
10 11 12 13 14 |
# File 'lib/braai/handlers/base.rb', line 10 def initialize(template, key, matches) @template = template @key = key @matches = matches end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
8 9 10 |
# File 'lib/braai/handlers/base.rb', line 8 def key @key end |
#matches ⇒ Object
Returns the value of attribute matches.
8 9 10 |
# File 'lib/braai/handlers/base.rb', line 8 def matches @matches end |
#template ⇒ Object
Returns the value of attribute template.
8 9 10 |
# File 'lib/braai/handlers/base.rb', line 8 def template @template end |
Class Method Details
.call(template, key, matches) ⇒ Object
18 19 20 21 |
# File 'lib/braai/handlers/base.rb', line 18 def call(template, key, matches) handler = self.new(template, key, matches) handler.safe_perform end |
Instance Method Details
#perform ⇒ Object
override this method in your own handlers
34 35 36 |
# File 'lib/braai/handlers/base.rb', line 34 def perform key end |
#rescue_from_error(e) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/braai/handlers/base.rb', line 38 def rescue_from_error(e) Braai::Handlers.rescuers.each do |rescuer| if e.is_a?(rescuer[:klass]) return rescuer[:handler].call(self, e) end end raise e end |
#safe_perform ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/braai/handlers/base.rb', line 24 def safe_perform value = begin perform rescue => e rescue_from_error(e) end value end |