Class: DotLocal::Mapper
- Inherits:
-
Object
show all
- Defined in:
- lib/dot_local/mapper.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(config, *args) ⇒ Mapper
Returns a new instance of Mapper.
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/dot_local/mapper.rb', line 4
def initialize(config, *args)
@parents = args.map!(&:to_s)
@config = config
@raw = config.raw
parents = @parents.dup
while parent = parents.shift
@raw = Mapper.fetch(@raw, parent)
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
20
21
22
23
|
# File 'lib/dot_local/mapper.rb', line 20
def method_missing(*args)
super if args.count > 1
return_value_or_mapper(args.first.to_s)
end
|
Class Method Details
.fetch(hash, key) ⇒ Object
25
26
27
28
29
|
# File 'lib/dot_local/mapper.rb', line 25
def self.fetch(hash, key)
hash.fetch(key)
rescue KeyError
raise KeyNotFound.new("You were looking for #{key} but no luck")
end
|
Instance Method Details
#to_hash ⇒ Object
31
32
33
|
# File 'lib/dot_local/mapper.rb', line 31
def to_hash
@raw if @raw.is_a?(Hash)
end
|