Class: Ecogem::Util::Config::ValueContainer
- Inherits:
-
Object
- Object
- Ecogem::Util::Config::ValueContainer
show all
- Defined in:
- lib/ecogem/util/config/value_container.rb
Defined Under Namespace
Classes: NotFoundError, Proxy, UnresolvedError
Instance Method Summary
collapse
Constructor Details
#initialize(base, config, default_data) ⇒ ValueContainer
Returns a new instance of ValueContainer.
5
6
7
8
9
|
# File 'lib/ecogem/util/config/value_container.rb', line 5
def initialize(base, config, default_data)
@base = base
@config = config
@default_data = default_data
end
|
Instance Method Details
#find_value(key) ⇒ Object
58
59
60
61
62
|
# File 'lib/ecogem/util/config/value_container.rb', line 58
def find_value(key)
return values[key] if values.key?(key)
return @base.find_value(key) if @base
raise NotFoundError
end
|
#h_to_values(h) ⇒ Object
19
20
21
22
23
24
25
26
27
|
# File 'lib/ecogem/util/config/value_container.rb', line 19
def h_to_values(h)
values = {}
h.each do |k, v|
k = k.to_sym
entry = @config.class.entries[k]
values[k] = entry.parse(v) if entry
end
values
end
|
#proxy ⇒ Object
11
12
13
|
# File 'lib/ecogem/util/config/value_container.rb', line 11
def proxy
@proxy ||= Proxy.new(self)
end
|
#resolve_method(name, *args, &block) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/ecogem/util/config/value_container.rb', line 38
def resolve_method(name, *args, &block)
key = name.to_s.sub(/(=)$/, '').to_sym
assign = $1
entry = @config.class.entries[key]
if entry
if assign
return values[key] = args.first
else
begin
return find_value(key)
rescue NotFoundError
value = entry.parse(nil)
values[key] = value
return value
end
end
end
raise UnresolvedError
end
|
#values ⇒ Object
15
16
17
|
# File 'lib/ecogem/util/config/value_container.rb', line 15
def values
@values ||= h_to_values(@default_data || {})
end
|
#values_to_h ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'lib/ecogem/util/config/value_container.rb', line 29
def values_to_h
h = {}
values.each do |k, v|
entry = @config.class.entries[k]
h[k.to_s] = entry.unparse(v)
end
h
end
|