An Environment is used to hold model elements.
Add a model element. Returns the environment so << can be chained.
# File lib/rgen/environment.rb, line 17 def <<(el) clazz = el.class @elements[clazz] ||= [] @elements[clazz] << el updateSubClasses(clazz) self end
Removes model element from environment.
# File lib/rgen/environment.rb, line 26 def delete(el) @deleted[el] = true @deletedClasses[el.class] = true end
Iterates each element
# File lib/rgen/environment.rb, line 33 def each(&b) removeDeleted @elements.values.flatten.each(&b) end
Return the elements of the environment as an array
# File lib/rgen/environment.rb, line 40 def elements removeDeleted @elements.values.flatten end
Finds and returns model elements in the environment.
The search description argument must be a hash specifying attribute/value pairs. Only model elements are returned which respond to the specified attribute methods and return the specified values as result of these attribute methods.
As a special hash key :class can be used to look for model elements of a specific class. In this case an array of possible classes can optionally be given.
# File lib/rgen/environment.rb, line 63 def find(desc) removeDeleted result = [] classes = desc[:class] if desc[:class] and desc[:class].is_a?(Array) classes = [ desc[:class] ] if !classes and desc[:class] if classes hashKeys = classesWithSubClasses(classes) else hashKeys = @elements.keys end hashKeys.each do |clazz| next unless @elements[clazz] @elements[clazz].each do |e| failed = false desc.each_pair { |k,v| failed = true if k != :class and ( !e.respond_to?(k) or e.send(k) != v ) } result << e unless failed end end result end
Generated with the Darkfish Rdoc Generator 2.