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) ⇒ Object
130
131
132
133
134
135
136
|
# File 'lib/compass/configuration/inheritance.rb', line 130
def method_missing(meth)
if inherited_data
inherited_data.send(meth)
else
raise NoMethodError, meth.to_s
end
end
|
Instance Method Details
#debug ⇒ Object
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/compass/configuration/inheritance.rb', line 148
def debug
instances = [self]
instances << instances.last.inherited_data while instances.last.inherited_data
normalized_attrs = {}
ATTRIBUTES.each do |prop|
values = []
instances.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
102
103
104
105
106
107
|
# File 'lib/compass/configuration/inheritance.rb', line 102
def default_for(attribute)
method = "default_#{attribute}".to_sym
if respond_to?(method)
send(method)
end
end
|
#inherit_from!(data) ⇒ Object
81
82
83
84
85
86
87
88
|
# File 'lib/compass/configuration/inheritance.rb', line 81
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
69
70
71
|
# File 'lib/compass/configuration/inheritance.rb', line 69
def on_top!
self.set_top_level(self)
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.
122
123
124
125
126
127
128
|
# File 'lib/compass/configuration/inheritance.rb', line 122
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
110
111
112
113
114
115
116
117
118
|
# File 'lib/compass/configuration/inheritance.rb', line 110
def read_without_default(attribute)
if set?(attribute)
send("raw_#{attribute}")
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
|
#respond_to?(meth) ⇒ Boolean
138
139
140
141
142
143
144
145
146
|
# File 'lib/compass/configuration/inheritance.rb', line 138
def respond_to?(meth)
if super
true
elsif inherited_data
inherited_data.respond_to?(meth)
else
false
end
end
|
#set?(attribute) ⇒ Boolean
97
98
99
100
|
# File 'lib/compass/configuration/inheritance.rb', line 97
def set?(attribute)
@set_attributes ||= {}
@set_attributes[attribute]
end
|
#set_top_level(new_top) ⇒ Object
73
74
75
76
77
78
|
# File 'lib/compass/configuration/inheritance.rb', line 73
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
90
91
92
93
94
95
|
# File 'lib/compass/configuration/inheritance.rb', line 90
def unset!(attribute)
@set_attributes ||= {}
send("#{attribute}=", nil)
@set_attributes.delete(attribute)
nil
end
|