Class: Amrita2::HashDelegator

Inherits:
Object
  • Object
show all
Includes:
DictionaryData
Defined in:
lib/amrita2/template.rb

Instance Method Summary collapse

Methods included from DictionaryData

===, #amrita_value

Constructor Details

#initialize(parent, &block) ⇒ HashDelegator

Returns a new instance of HashDelegator.



2568
2569
2570
2571
2572
# File 'lib/amrita2/template.rb', line 2568

def initialize(parent, &block)
  @parent = parent
  @added_data = block.call
  raise 'block did not return a Hash' unless @added_data.kind_of?(DictionaryData)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
# File 'lib/amrita2/template.rb', line 2584

def method_missing(sym, *args, &block)
  if @added_data.has_key?(sym)
    @added_data[sym]
  else
    if @parent.kind_of?(DictionaryData)
      @parent.amrita_value(sym)
    else
      @parent.send(sym)
    end
  end
end

Instance Method Details

#[](key) ⇒ Object



2574
2575
2576
2577
2578
# File 'lib/amrita2/template.rb', line 2574

def [](key)
  self.send(key)
rescue NoMethodError
  nil
end

#idObject



2580
2581
2582
# File 'lib/amrita2/template.rb', line 2580

def id
  @parent.id
end