module RGen::MetamodelBuilder::BuilderRuntime
This module is mixed into MetamodelBuilder::MMBase. The methods provided by this module are used by the methods generated by the class methods of MetamodelBuilder::BuilderExtensions
Public Instance Methods
_add_contained_element(element)
click to toggle source
# File lib/rgen/metamodel_builder/builder_runtime.rb, line 147 def _add_contained_element(element) @_contained_elements ||= [] @_contained_elements << element end
_assignmentTypeError(target, value, expected)
click to toggle source
# File lib/rgen/metamodel_builder/builder_runtime.rb, line 156 def _assignmentTypeError(target, value, expected) text = "" if target targetId = target.class.name targetId += "(" + target.name + ")" if target.respond_to?(:name) and target.name text += "In #{targetId} : " end valueId = value.class.name valueId += "(" + value.name + ")" if value.respond_to?(:name) and value.name valueId += "(:" + value.to_s + ")" if value.is_a?(Symbol) text += "Can not use a #{valueId} where a #{expected} is expected" StandardError.new(text) end
_remove_contained_element(element)
click to toggle source
# File lib/rgen/metamodel_builder/builder_runtime.rb, line 152 def _remove_contained_element(element) @_contained_elements.delete(element) if @_contained_elements end
_set_container(container, containing_feature_name)
click to toggle source
# File lib/rgen/metamodel_builder/builder_runtime.rb, line 131 def _set_container(container, containing_feature_name) # if a new container is set, make sure to disconnect from the old one. # note that _set_container will never be called for the container and the role # which are currently set because the accessor methods in BuilderExtensions # block setting/adding a value which is already present. # (it may be called for the same container with a different role, a different container # with the same role and a different container with a different role, though) # this ensures, that disconnecting for the current container doesn't break # a new connection which has just been set up in the accessor methods. disconnectContainer if container @_container._remove_contained_element(self) if @_container container._add_contained_element(self) if container @_container = container @_containing_feature_name = containing_feature_name end
addGeneric(role, value, index=-1)
click to toggle source
# File lib/rgen/metamodel_builder/builder_runtime.rb, line 21 def addGeneric(role, value, index=-1) send("add#{firstToUpper(role.to_s)}",value, index) end
disconnectContainer()
click to toggle source
# File lib/rgen/metamodel_builder/builder_runtime.rb, line 127 def disconnectContainer eContainer.setNilOrRemoveGeneric(eContainingFeature, self) if eContainer end
eAllContents(&block)
click to toggle source
if a block is given, calls the block on every contained element in depth first order. if the block returns :prune, recursion will stop at this point.
if no block is given builds and returns a list of all contained elements.
# File lib/rgen/metamodel_builder/builder_runtime.rb, line 106 def eAllContents(&block) if block if @_contained_elements @_contained_elements.each do |e| res = block.call(e) e.eAllContents(&block) if res != :prune end end nil else result = [] if @_contained_elements @_contained_elements.each do |e| result << e result.concat(e.eAllContents) end end result end end
eContainer()
click to toggle source
# File lib/rgen/metamodel_builder/builder_runtime.rb, line 84 def eContainer @_container end
eContainingFeature()
click to toggle source
# File lib/rgen/metamodel_builder/builder_runtime.rb, line 88 def eContainingFeature @_containing_feature_name end
eContents()
click to toggle source
returns the contained elements in no particular order
# File lib/rgen/metamodel_builder/builder_runtime.rb, line 93 def eContents if @_contained_elements @_contained_elements.dup else [] end end
eIsSet(role)
click to toggle source
# File lib/rgen/metamodel_builder/builder_runtime.rb, line 71 def eIsSet(role) eval("defined? @#{role}") != nil end
eUnset(role)
click to toggle source
# File lib/rgen/metamodel_builder/builder_runtime.rb, line 75 def eUnset(role) if respond_to?("add#{firstToUpper(role.to_s)}") setGeneric(role, []) else setGeneric(role, nil) end remove_instance_variable("@#{role}") end
getGeneric(role)
click to toggle source
# File lib/rgen/metamodel_builder/builder_runtime.rb, line 61 def getGeneric(role) send("get#{firstToUpper(role.to_s)}") end
getGenericAsArray(role)
click to toggle source
# File lib/rgen/metamodel_builder/builder_runtime.rb, line 65 def getGenericAsArray(role) result = getGeneric(role) result = [result].compact unless result.is_a?(Array) result end
hasManyMethods(role)
click to toggle source
# File lib/rgen/metamodel_builder/builder_runtime.rb, line 33 def hasManyMethods(role) respond_to?("add#{firstToUpper(role.to_s)}") end
is_a?(c)
click to toggle source
Calls superclass method
# File lib/rgen/metamodel_builder/builder_runtime.rb, line 16 def is_a?(c) return super unless c.const_defined?(:ClassModule) kind_of?(c::ClassModule) end
removeGeneric(role, value)
click to toggle source
# File lib/rgen/metamodel_builder/builder_runtime.rb, line 25 def removeGeneric(role, value) send("remove#{firstToUpper(role.to_s)}",value) end
setGeneric(role, value)
click to toggle source
# File lib/rgen/metamodel_builder/builder_runtime.rb, line 29 def setGeneric(role, value) send("set#{firstToUpper(role.to_s)}",value) end
setNilOrRemoveAllGeneric(role)
click to toggle source
# File lib/rgen/metamodel_builder/builder_runtime.rb, line 53 def setNilOrRemoveAllGeneric(role) if hasManyMethods(role) setGeneric(role, []) else setGeneric(role, nil) end end
setNilOrRemoveGeneric(role, value)
click to toggle source
# File lib/rgen/metamodel_builder/builder_runtime.rb, line 45 def setNilOrRemoveGeneric(role, value) if hasManyMethods(role) removeGeneric(role, value) else setGeneric(role, nil) end end
setOrAddGeneric(role, value)
click to toggle source
# File lib/rgen/metamodel_builder/builder_runtime.rb, line 37 def setOrAddGeneric(role, value) if hasManyMethods(role) addGeneric(role, value) else setGeneric(role, value) end end