Class: Construct
- Inherits:
-
Object
show all
- Defined in:
- lib/rake/config.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
134
135
136
137
138
139
140
141
142
|
# File 'lib/rake/config.rb', line 134
def method_missing(meth, *args)
Thread.current[:confStack].calling(self, meth, :method_missing, args);
begin
resultObject = orig_method_missing(meth, *args);
rescue NoMethodError => errorObject
Thread.current[:confStack].reportNoMethodError(errorObject);
end
resultObject
end
|
Instance Method Details
#[](key) ⇒ Object
145
146
147
148
|
# File 'lib/rake/config.rb', line 145
def [](key)
Thread.current[:confStack].calling(self, key, :key_lookup);
orig_key_lookup(key)
end
|
#[]=(key, value) ⇒ Object
151
152
153
154
155
156
157
158
|
# File 'lib/rake/config.rb', line 151
def []=(key, value)
value = Hash.new() if value.nil?;
if @data.include?(key) && @data[key].is_a?(Construct) && (value.is_a?(Hash) || value.is_a?(Construct)) then
value = @data[key].merge(value);
end
orig_key_value_assignment(key, value);
end
|
#each_key(*args, &block) ⇒ Object
129
130
131
|
# File 'lib/rake/config.rb', line 129
def each_key(*args, &block)
@data.each_key(*args, &block)
end
|
#each_pair(*args, &block) ⇒ Object
125
126
127
|
# File 'lib/rake/config.rb', line 125
def each_pair(*args, &block)
@data.each_pair(*args, &block)
end
|
#empty? ⇒ Boolean
117
118
119
|
# File 'lib/rake/config.rb', line 117
def empty?()
@data.empty?();
end
|
#has_key?(key) ⇒ Boolean
121
122
123
|
# File 'lib/rake/config.rb', line 121
def has_key?(key)
@data.has_key?(key);
end
|
#merge(valueToMerge) ⇒ Object
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
# File 'lib/rake/config.rb', line 160
def merge(valueToMerge)
if valueToMerge.is_a?(Hash) || valueToMerge.is_a?(Construct) then
valueToMerge.each do | key, value |
key = key.to_sym;
if value.is_a?(Hash) || value.is_a?(Construct) then
self[key] = Construct.new() unless self.has_key?(key);
if !self[key].is_a?(Construct) then
raise ArgumentError, "attempting to merge a Hash/Construct into an existing non Hash/Construct key [#{key}]";
end
self[key].merge(value);
elsif value.is_a?(Array) then
self[key] = Array.new() unless self.has_key?(key);
if !self[key].is_a?(Array) then
raise ArgumentError, "attempting to merge an Array into an existing non Array key [#{key}]";
end
value.each do | item |
self[key].push(item);
end
else
self[key] = value;
end
end
end
if valueToMerge.is_a?(Construct) then
@schema.merge(valueToMerge.schema);
end
return self;
end
|
#orig_key_lookup ⇒ Object
144
|
# File 'lib/rake/config.rb', line 144
alias_method :orig_key_lookup, :[]
|
#orig_key_value_assignment ⇒ Object
150
|
# File 'lib/rake/config.rb', line 150
alias_method :orig_key_value_assignment, :[]=
|
#orig_method_missing ⇒ Object
133
|
# File 'lib/rake/config.rb', line 133
alias_method :orig_method_missing, :method_missing
|
#to_stringHash ⇒ Object
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/rake/config.rb', line 189
def to_stringHash()
result = Hash.new();
data.each_pair do | aKey, aValue |
if aValue.is_a?(Construct) then
aValue = aValue.to_stringHash();
end
result[aKey.to_s] = aValue;
end
return result;
end
|