Class: Braai::Context

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(substrate, template, attributes = {}) ⇒ Context

Returns a new instance of Context.



5
6
7
8
9
10
# File 'lib/braai/context.rb', line 5

def initialize(substrate, template, attributes = {})
  self.attributes = HashWithIndifferentAccess.new(attributes)
  self.substrate = substrate.dup
  self.matchers = template.matchers
  self.fallback = template.fallback
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



3
4
5
# File 'lib/braai/context.rb', line 3

def attributes
  @attributes
end

#fallbackObject

Returns the value of attribute fallback.



3
4
5
# File 'lib/braai/context.rb', line 3

def fallback
  @fallback
end

#matchersObject

Returns the value of attribute matchers.



3
4
5
# File 'lib/braai/context.rb', line 3

def matchers
  @matchers
end

#substrateObject

Returns the value of attribute substrate.



3
4
5
# File 'lib/braai/context.rb', line 3

def substrate
  @substrate
end

Instance Method Details

#renderObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/braai/context.rb', line 12

def render
  begin

    self.matchers.each do |regex, matcher|
      substitute(regex, matcher)
    end

    if self.fallback
      substitute(self.fallback[:regex], self.fallback[:handler])
    end

    return self.substrate
  rescue Exception => e
    Braai.logger.error(e)
    raise e unless Braai.config.swallow_matcher_errors
  end
end