Class: Rubber::Configuration::Environment::HashValueProxy
- Inherits:
-
Hash
- Object
- Hash
- Rubber::Configuration::Environment::HashValueProxy
show all
- Defined in:
- lib/rubber/environment.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(global, receiver) ⇒ HashValueProxy
Returns a new instance of HashValueProxy.
74
75
76
77
78
|
# File 'lib/rubber/environment.rb', line 74
def initialize(global, receiver)
@global = global
super()
replace(receiver)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id) ⇒ Object
92
93
94
95
|
# File 'lib/rubber/environment.rb', line 92
def method_missing(method_id)
key = method_id.id2name
return self[key]
end
|
Instance Attribute Details
#global ⇒ Object
Returns the value of attribute global.
72
73
74
|
# File 'lib/rubber/environment.rb', line 72
def global
@global
end
|
Instance Method Details
#[](name) ⇒ Object
80
81
82
83
84
|
# File 'lib/rubber/environment.rb', line 80
def [](name)
value = super(name)
value = global[name] if global && !value
return expand(value)
end
|
#each ⇒ Object
86
87
88
89
90
|
# File 'lib/rubber/environment.rb', line 86
def each
each_key do |key|
yield key, self[key]
end
end
|
#expand(value) ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/rubber/environment.rb', line 106
def expand(value)
val = case value
when Hash
HashValueProxy.new(global || self, value)
when String
expand_string(value)
when Enumerable
value.collect {|v| expand(v) }
else
value
end
return val
end
|
#expand_string(val) ⇒ Object
97
98
99
100
101
102
103
104
|
# File 'lib/rubber/environment.rb', line 97
def expand_string(val)
while val =~ /\#\{[^\}]+\}/
val = eval('%Q{' + val + '}', binding)
end
val = true if val =="true"
val = false if val == "false"
return val
end
|