Class: Rubber::Configuration::Environment::HashValueProxy
- Inherits:
-
Hash
- Object
- Hash
- Rubber::Configuration::Environment::HashValueProxy
show all
- Includes:
- MonitorMixin
- 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.
143
144
145
146
147
148
|
# File 'lib/rubber/environment.rb', line 143
def initialize(global, receiver)
@global = global
@cache = {}
super()
replace(receiver)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id) ⇒ Object
182
183
184
|
# File 'lib/rubber/environment.rb', line 182
def method_missing(method_id)
self[method_id.id2name]
end
|
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache.
141
142
143
|
# File 'lib/rubber/environment.rb', line 141
def cache
@cache
end
|
#global ⇒ Object
Returns the value of attribute global.
141
142
143
|
# File 'lib/rubber/environment.rb', line 141
def global
@global
end
|
Instance Method Details
#[](name) ⇒ Object
158
159
160
161
162
163
164
165
166
167
168
|
# File 'lib/rubber/environment.rb', line 158
def [](name)
unless cache.has_key?(name)
synchronize do
value = super(name)
value = global[name] if global && !value
cache[name] = expand(value)
end
end
cache[name]
end
|
#each ⇒ Object
170
171
172
173
174
|
# File 'lib/rubber/environment.rb', line 170
def each
each_key do |key|
yield key, self[key]
end
end
|
#expand(value) ⇒ Object
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
# File 'lib/rubber/environment.rb', line 197
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
val
end
|
#expand_string(val) ⇒ Object
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/rubber/environment.rb', line 186
def expand_string(val)
while val =~ /\#\{[^\}]+\}/
val = eval('%Q{' + val + '}', binding, __FILE__)
end
val = true if val =="true"
val = false if val == "false"
val
end
|
#rubber_instances ⇒ Object
150
151
152
|
# File 'lib/rubber/environment.rb', line 150
def rubber_instances
Rubber.instances
end
|
#to_a ⇒ Object
allows expansion when to_a gets called on hash proxy, e.g. when wrapping a var in Array() to ensure error free iteration for possible null values
178
179
180
|
# File 'lib/rubber/environment.rb', line 178
def to_a
self.collect {|k, v| [k, v]}
end
|