Module: Compass::Configuration::Inheritance::InstanceMethods
- Defined in:
- lib/compass/configuration/inheritance.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
263
264
265
266
267
268
269
|
# File 'lib/compass/configuration/inheritance.rb', line 263
def method_missing(meth, *args, &block)
if inherited_data
inherited_data.send(meth, *args, &block)
else
raise NoMethodError, meth.to_s
end
end
|
Instance Method Details
#any_attributes_set? ⇒ Boolean
223
224
225
|
# File 'lib/compass/configuration/inheritance.rb', line 223
def any_attributes_set?
@set_attributes && @set_attributes.size > 0
end
|
#chain ⇒ Object
281
282
283
284
285
|
# File 'lib/compass/configuration/inheritance.rb', line 281
def chain
instances = [self]
instances << instances.last.inherited_data while instances.last.inherited_data
instances
end
|
#debug ⇒ Object
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
# File 'lib/compass/configuration/inheritance.rb', line 287
def debug
normalized_attrs = {}
(ATTRIBUTES + ARRAY_ATTRIBUTES).each do |prop|
values = []
chain.each do |instance|
values << {
:raw => (instance.send("raw_#{prop}") rescue nil),
:value => (instance.send("#{prop}_without_default") rescue nil),
:default => (instance.send("default_#{prop}") rescue nil),
:resolved => instance.send(prop)
}
end
normalized_attrs[prop] = values
end
normalized_attrs
end
|
#default_for(attribute) ⇒ Object
227
228
229
230
231
232
|
# File 'lib/compass/configuration/inheritance.rb', line 227
def default_for(attribute)
method = "default_#{attribute}".to_sym
if respond_to?(method)
send(method)
end
end
|
#inherit_from!(data) ⇒ Object
192
193
194
195
196
197
198
199
|
# File 'lib/compass/configuration/inheritance.rb', line 192
def inherit_from!(data)
if self.inherited_data
self.inherited_data.inherit_from!(data)
else
self.inherited_data = data
end
self
end
|
#on_top! ⇒ Object
180
181
182
|
# File 'lib/compass/configuration/inheritance.rb', line 180
def on_top!
self.set_top_level(self)
end
|
#raw(attribute) ⇒ Object
Reads the raw value that was set on this object. you generally should call raw_<attribute>() instead.
249
250
251
|
# File 'lib/compass/configuration/inheritance.rb', line 249
def raw(attribute)
instance_variable_get("@#{attribute}")
end
|
#read(attribute) ⇒ Object
Read a value that is either inherited or set on this instance, if we get to the bottom-most configuration instance, we ask for the default starting at the top level.
255
256
257
258
259
260
261
|
# File 'lib/compass/configuration/inheritance.rb', line 255
def read(attribute)
if !(v = send("#{attribute}_without_default")).nil?
v
else
top_level.default_for(attribute)
end
end
|
#read_without_default(attribute) ⇒ Object
Read an explicitly set value that is either inherited or set on this instance
235
236
237
238
239
240
241
242
243
244
245
|
# File 'lib/compass/configuration/inheritance.rb', line 235
def read_without_default(attribute)
if set?(attribute)
send("raw_#{attribute}")
elsif inherited_data.nil?
nil
elsif inherited_data.respond_to?("#{attribute}_without_default")
inherited_data.send("#{attribute}_without_default")
elsif inherited_data.respond_to?(attribute)
inherited_data.send(attribute)
end
end
|
#reset_inheritance! ⇒ Object
201
202
203
|
# File 'lib/compass/configuration/inheritance.rb', line 201
def reset_inheritance!
self.inherited_data = nil
end
|
#respond_to?(meth) ⇒ Boolean
271
272
273
274
275
276
277
278
279
|
# File 'lib/compass/configuration/inheritance.rb', line 271
def respond_to?(meth)
if super
true
elsif inherited_data
inherited_data.respond_to?(meth)
else
false
end
end
|
#set?(attribute) ⇒ Boolean
218
219
220
221
|
# File 'lib/compass/configuration/inheritance.rb', line 218
def set?(attribute)
@set_attributes ||= {}
@set_attributes[attribute]
end
|
#set_top_level(new_top) ⇒ Object
184
185
186
187
188
189
|
# File 'lib/compass/configuration/inheritance.rb', line 184
def set_top_level(new_top)
self.top_level = new_top
if self.inherited_data.respond_to?(:set_top_level)
self.inherited_data.set_top_level(new_top)
end
end
|
#unset!(attribute) ⇒ Object
211
212
213
214
215
216
|
# File 'lib/compass/configuration/inheritance.rb', line 211
def unset!(attribute)
@set_attributes ||= {}
send("#{attribute}=", nil)
@set_attributes.delete(attribute)
nil
end
|
#with_defaults(data) ⇒ Object
205
206
207
208
209
|
# File 'lib/compass/configuration/inheritance.rb', line 205
def with_defaults(data)
inherit_from!(data)
yield
reset_inheritance!
end
|