Class: Braai::Handlers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/braai/handlers/base.rb

Direct Known Subclasses

Default, Iteration

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#keyObject

Returns the value of attribute key.



8
9
10
# File 'lib/braai/handlers/base.rb', line 8

def key
  @key
end

#matchesObject

Returns the value of attribute matches.



8
9
10
# File 'lib/braai/handlers/base.rb', line 8

def matches
  @matches
end

#templateObject

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

#performObject

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_performObject



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