Class: Construct

Inherits:
Object
  • 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



138
139
140
141
142
143
144
145
146
# File 'lib/rake/config.rb', line 138

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



149
150
151
152
# File 'lib/rake/config.rb', line 149

def [](key)
  Thread.current[:confStack].calling(self, key, :key_lookup);
  orig_key_lookup(key)
end

#[]=(key, value) ⇒ Object



155
156
157
158
159
160
161
162
# File 'lib/rake/config.rb', line 155

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

#cloneDataObject



117
118
119
# File 'lib/rake/config.rb', line 117

def cloneData()
  @data = @data.clone;
end

#each_key(*args, &block) ⇒ Object



133
134
135
# File 'lib/rake/config.rb', line 133

def each_key(*args, &block)
  @data.each_key(*args, &block)
end

#each_pair(*args, &block) ⇒ Object



129
130
131
# File 'lib/rake/config.rb', line 129

def each_pair(*args, &block)
  @data.each_pair(*args, &block)
end

#empty?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/rake/config.rb', line 121

def empty?()
  @data.empty?();
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/rake/config.rb', line 125

def has_key?(key)
  @data.has_key?(key);
end

#merge(valueToMerge) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/rake/config.rb', line 164

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_lookupObject



148
# File 'lib/rake/config.rb', line 148

alias_method :orig_key_lookup, :[]

#orig_key_value_assignmentObject



154
# File 'lib/rake/config.rb', line 154

alias_method :orig_key_value_assignment, :[]=

#orig_method_missingObject



137
# File 'lib/rake/config.rb', line 137

alias_method :orig_method_missing, :method_missing

#prettyPrint(result, prefix) ⇒ Object



204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/rake/config.rb', line 204

def prettyPrint(result, prefix)
  if empty? then
    result.puts(prefix+'=emptyConstruct');
  else
    data.keys.sort{ |x,y| x.to_s <=> y.to_s }.each do | aKey |
      aValue = data[aKey];
      if aValue.respond_to?(:prettyPrint) then
        aValue.prettyPrint(result, prefix+'.'+aKey.to_s);
      else
        result.puts(prefix+'.'+aKey.to_s+"="+aValue.to_s);
      end
    end
  end
end

#to_stringHashObject



193
194
195
196
197
198
199
200
201
202
# File 'lib/rake/config.rb', line 193

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