Class: Praxis::Mapper::ConfigHash
- Inherits:
- BasicObject
- Defined in:
- lib/praxis-mapper/config_hash.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash = {}, &block) ⇒ ConfigHash
constructor
A new instance of ConfigHash.
- #method_missing(name, value, *rest, &block) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(hash = {}, &block) ⇒ ConfigHash
Returns a new instance of ConfigHash.
10 11 12 13 |
# File 'lib/praxis-mapper/config_hash.rb', line 10 def initialize(hash={},&block) @hash = hash @block = block end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, value, *rest, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/praxis-mapper/config_hash.rb', line 20 def method_missing(name, value, *rest, &block) if (existing = @hash[name]) if block existing << [value, block] else existing << value rest.each do |v| existing << v end end else if rest.any? @hash[name] = [value] + rest else @hash[name] = value end end end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
4 5 6 |
# File 'lib/praxis-mapper/config_hash.rb', line 4 def hash @hash end |
Class Method Details
.from(hash = {}, &block) ⇒ Object
6 7 8 |
# File 'lib/praxis-mapper/config_hash.rb', line 6 def self.from(hash={},&block) self.new(hash,&block) end |
Instance Method Details
#to_hash ⇒ Object
15 16 17 18 |
# File 'lib/praxis-mapper/config_hash.rb', line 15 def to_hash self.instance_eval(&@block) @hash end |