Module: Braai::Helpers

Included in:
Braai::Handlers::Conditional, Braai::Handlers::Default
Defined in:
lib/braai/helpers.rb

Instance Method Summary collapse

Instance Method Details

#resolve_variable_chain_value(str) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/braai/helpers.rb', line 3

def resolve_variable_chain_value(str)
  value = nil
  chain = str.split('.')

  if template.attributes.has_key?(chain.first)
    value = template.attributes[chain.shift] || ''
  else
    return nil unless value
  end

  chain.each do |a|
    if value.respond_to?(a.to_sym)
      value = value.send(a) || ''
    elsif value.is_a?(Hash)
      if value.has_key?(a.to_sym) || value.has_key?(a.to_s)
        value = value[a.to_sym] || value[a.to_s] || ''
      else
        return nil
      end
    else
      return nil
    end
  end

  value
end