Module: RGen::MetamodelBuilder::BuilderExtensions
- Includes:
- Util::NameHelper
- Included in:
- MMBase
- Defined in:
- lib/rgen/metamodel_builder/builder_extensions.rb
Overview
This module provides methods which can be used to setup a metamodel element. The module is used to extend
MetamodelBuilder::MMBase, i.e. add the module’s methods as class methods.
MetamodelBuilder::MMBase should be used as a start for new metamodel elements. See MetamodelBuilder for an example.
Defined Under Namespace
Classes: FeatureBlockEvaluator
Instance Method Summary collapse
- #_abstract_class ⇒ Object
-
#_add_metamodel_description(desc) ⇒ Object
:nodoc.
-
#_metamodel_description ⇒ Object
:nodoc:.
- #abstract ⇒ Object
- #contains_many(target_role, target_class, own_role, raw_props = {}, &block) ⇒ Object
- #contains_many_uni(role, target_class = nil, raw_props = {}, &block) ⇒ Object
- #contains_one(target_role, target_class, own_role, raw_props = {}, &block) ⇒ Object
- #contains_one_uni(role, target_class = nil, raw_props = {}, &block) ⇒ Object
-
#has_attr(role, target_class = nil, raw_props = {}, &block) ⇒ Object
Add an attribute which can hold a single value.
-
#has_many(role, target_class = nil, raw_props = {}, &block) ⇒ Object
Add an unidirectional many association.
-
#has_many_attr(role, target_class = nil, raw_props = {}, &block) ⇒ Object
Add an attribute which can hold multiple values.
-
#has_one(role, target_class = nil, raw_props = {}, &block) ⇒ Object
Add a single unidirectional association.
- #inherited(c) ⇒ Object
-
#many_to_many(target_role, target_class, own_role, raw_props = {}, &block) ⇒ Object
Add a bidirectional many-to-many association between two classes.
-
#many_to_one(target_role, target_class, own_role, raw_props = {}, &block) ⇒ Object
This is the inverse of one_to_many provided for convenience.
-
#one_to_many(target_role, target_class, own_role, raw_props = {}, &block) ⇒ Object
Add a bidirectional one-to-many association between two classes.
-
#one_to_one(target_role, target_class, own_role, raw_props = {}, &block) ⇒ Object
Add a bidirectional one-to-one association between two classes.
Methods included from Util::NameHelper
#camelize, #className, #firstToLower, #firstToUpper, #normalize, #saneClassName, #saneMethodName
Instance Method Details
#_abstract_class ⇒ Object
263 264 265 |
# File 'lib/rgen/metamodel_builder/builder_extensions.rb', line 263 def _abstract_class @abstract || false end |
#_add_metamodel_description(desc) ⇒ Object
:nodoc
251 252 253 254 255 256 257 |
# File 'lib/rgen/metamodel_builder/builder_extensions.rb', line 251 def (desc) # :nodoc @metamodel_description ||= [] @metamodelDescriptionByName ||= {} @metamodel_description.delete(@metamodelDescriptionByName[desc.value(:name)]) @metamodel_description << desc @metamodelDescriptionByName[desc.value(:name)] = desc end |
#_metamodel_description ⇒ Object
:nodoc:
247 248 249 |
# File 'lib/rgen/metamodel_builder/builder_extensions.rb', line 247 def # :nodoc: @metamodel_description ||= [] end |
#abstract ⇒ Object
259 260 261 |
# File 'lib/rgen/metamodel_builder/builder_extensions.rb', line 259 def abstract @abstract = true end |
#contains_many(target_role, target_class, own_role, raw_props = {}, &block) ⇒ Object
161 162 163 164 165 166 167 168 |
# File 'lib/rgen/metamodel_builder/builder_extensions.rb', line 161 def contains_many(target_role, target_class, own_role, raw_props={}, &block) props1 = Intermediate::Reference.new(target_class, _setManyUpperBound(_ownProps(raw_props).merge({ :name=>target_role, :containment=>true}))) props2 = Intermediate::Reference.new(self, _oppositeProps(raw_props).merge({ :name=>own_role, :upperBound=>1, :containment=>false})) FeatureBlockEvaluator.eval(block, props1, props2) _build_internal(props1, props2) end |
#contains_many_uni(role, target_class = nil, raw_props = {}, &block) ⇒ Object
123 124 125 126 127 128 129 |
# File 'lib/rgen/metamodel_builder/builder_extensions.rb', line 123 def contains_many_uni(role, target_class=nil, raw_props={}, &block) props = Intermediate::Reference.new(target_class, _setManyUpperBound(_ownProps(raw_props).merge({ :name=>role, :containment=>true}))) raise "No opposite available" unless _oppositeProps(raw_props).empty? FeatureBlockEvaluator.eval(block, props) _build_internal(props) end |
#contains_one(target_role, target_class, own_role, raw_props = {}, &block) ⇒ Object
238 239 240 241 242 243 244 245 |
# File 'lib/rgen/metamodel_builder/builder_extensions.rb', line 238 def contains_one(target_role, target_class, own_role, raw_props={}, &block) props1 = Intermediate::Reference.new(target_class, _ownProps(raw_props).merge({ :name=>target_role, :upperBound=>1, :containment=>true})) props2 = Intermediate::Reference.new(self, _oppositeProps(raw_props).merge({ :name=>own_role, :upperBound=>1, :containment=>false})) FeatureBlockEvaluator.eval(block, props1, props2) _build_internal(props1, props2) end |
#contains_one_uni(role, target_class = nil, raw_props = {}, &block) ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/rgen/metamodel_builder/builder_extensions.rb', line 115 def contains_one_uni(role, target_class=nil, raw_props={}, &block) props = Intermediate::Reference.new(target_class, _ownProps(raw_props).merge({ :name=>role, :upperBound=>1, :containment=>true})) raise "No opposite available" unless _oppositeProps(raw_props).empty? FeatureBlockEvaluator.eval(block, props) _build_internal(props) end |
#has_attr(role, target_class = nil, raw_props = {}, &block) ⇒ Object
Add an attribute which can hold a single value. ‘role’ specifies the name which is used to access the attribute. ‘target_class’ specifies the type of objects which can be held by this attribute. If no target class is given, String will be default.
This class method adds the following instance methods, where ‘role’ is to be replaced by the given role name:
class#role # getter
class#role=(value) # setter
48 49 50 51 52 53 54 |
# File 'lib/rgen/metamodel_builder/builder_extensions.rb', line 48 def has_attr(role, target_class=nil, raw_props={}, &block) props = Intermediate::Attribute.new(target_class, _ownProps(raw_props).merge({ :name=>role, :upperBound=>1})) raise "No opposite available" unless _oppositeProps(raw_props).empty? FeatureBlockEvaluator.eval(block, props) _build_internal(props) end |
#has_many(role, target_class = nil, raw_props = {}, &block) ⇒ Object
Add an unidirectional many association. ‘role’ specifies the name which is used to access the attribute. ‘target_class’ is optional and can be used to fix the type of objects which can be referenced by this association.
This class method adds the following instance methods, where ‘role’ is to be replaced by the given role name:
class#addRole(value, index=-1)
class#removeRole(value)
class#role # getter, returns an array
Note that the first letter of the role name is turned into an uppercase for the add and remove methods.
107 108 109 110 111 112 113 |
# File 'lib/rgen/metamodel_builder/builder_extensions.rb', line 107 def has_many(role, target_class=nil, raw_props={}, &block) props = Intermediate::Reference.new(target_class, _setManyUpperBound(_ownProps(raw_props).merge({ :name=>role, :containment=>false}))) raise "No opposite available" unless _oppositeProps(raw_props).empty? FeatureBlockEvaluator.eval(block, props) _build_internal(props) end |
#has_many_attr(role, target_class = nil, raw_props = {}, &block) ⇒ Object
Add an attribute which can hold multiple values. ‘role’ specifies the name which is used to access the attribute. ‘target_class’ specifies the type of objects which can be held by this attribute. If no target class is given, String will be default.
This class method adds the following instance methods, where ‘role’ is to be replaced by the given role name:
class#addRole(value, index=-1)
class#removeRole(value)
class#role # getter, returns an array
class#role= # setter, sets multiple values at once
Note that the first letter of the role name is turned into an uppercase for the add and remove methods.
69 70 71 72 73 74 75 |
# File 'lib/rgen/metamodel_builder/builder_extensions.rb', line 69 def has_many_attr(role, target_class=nil, raw_props={}, &block) props = Intermediate::Attribute.new(target_class, _setManyUpperBound(_ownProps(raw_props).merge({ :name=>role}))) raise "No opposite available" unless _oppositeProps(raw_props).empty? FeatureBlockEvaluator.eval(block, props) _build_internal(props) end |
#has_one(role, target_class = nil, raw_props = {}, &block) ⇒ Object
Add a single unidirectional association. ‘role’ specifies the name which is used to access the association. ‘target_class’ specifies the type of objects which can be held by this association.
This class method adds the following instance methods, where ‘role’ is to be replaced by the given role name:
class#role # getter
class#role=(value) # setter
86 87 88 89 90 91 92 |
# File 'lib/rgen/metamodel_builder/builder_extensions.rb', line 86 def has_one(role, target_class=nil, raw_props={}, &block) props = Intermediate::Reference.new(target_class, _ownProps(raw_props).merge({ :name=>role, :upperBound=>1, :containment=>false})) raise "No opposite available" unless _oppositeProps(raw_props).empty? FeatureBlockEvaluator.eval(block, props) _build_internal(props) end |
#inherited(c) ⇒ Object
267 268 269 270 |
# File 'lib/rgen/metamodel_builder/builder_extensions.rb', line 267 def inherited(c) c.send(:include, c.const_set(:ClassModule, Module.new)) MetamodelBuilder::ConstantOrderHelper.classCreated(c) end |
#many_to_many(target_role, target_class, own_role, raw_props = {}, &block) ⇒ Object
Add a bidirectional many-to-many association between two classes. The class this method is called on is refered to as own_class in the following.
Instances of own_class can use ‘own_role’ to access many associated instances of type ‘target_class’. Instances of ‘target_class’ can use ‘target_role’ to access many associated instances of own_class.
This class method adds the following instance methods where ‘ownRole’ and ‘targetRole’ are to be replaced by the given role names:
own_class#addOwnRole(value, index=-1)
own_class#removeOwnRole(value)
own_class#ownRole
target_class#addTargetRole
target_class#removeTargetRole=(value)
target_class#targetRole
Note that the first letter of the role name is turned into an uppercase for the add and remove methods.
When an element is added on either side, this element also receives the element is is added to as a new element.
202 203 204 205 206 207 208 209 |
# File 'lib/rgen/metamodel_builder/builder_extensions.rb', line 202 def many_to_many(target_role, target_class, own_role, raw_props={}, &block) props1 = Intermediate::Reference.new(target_class, _setManyUpperBound(_ownProps(raw_props).merge({ :name=>target_role, :containment=>false}))) props2 = Intermediate::Reference.new(self, _setManyUpperBound(_oppositeProps(raw_props).merge({ :name=>own_role, :containment=>false}))) FeatureBlockEvaluator.eval(block, props1, props2) _build_internal(props1, props2) end |
#many_to_one(target_role, target_class, own_role, raw_props = {}, &block) ⇒ Object
This is the inverse of one_to_many provided for convenience.
171 172 173 174 175 176 177 178 |
# File 'lib/rgen/metamodel_builder/builder_extensions.rb', line 171 def many_to_one(target_role, target_class, own_role, raw_props={}, &block) props1 = Intermediate::Reference.new(target_class, _ownProps(raw_props).merge({ :name=>target_role, :upperBound=>1, :containment=>false})) props2 = Intermediate::Reference.new(self, _setManyUpperBound(_oppositeProps(raw_props).merge({ :name=>own_role, :containment=>false}))) FeatureBlockEvaluator.eval(block, props1, props2) _build_internal(props1, props2) end |
#one_to_many(target_role, target_class, own_role, raw_props = {}, &block) ⇒ Object
Add a bidirectional one-to-many association between two classes. The class this method is called on is refered to as own_class in the following.
Instances of own_class can use ‘own_role’ to access many associated instances of type ‘target_class’. Instances of ‘target_class’ can use ‘target_role’ to access one associated instance of own_class.
This class method adds the following instance methods where ‘ownRole’ and ‘targetRole’ are to be replaced by the given role names:
own_class#addOwnRole(value, index=-1)
own_class#removeOwnRole(value)
own_class#ownRole
target_class#targetRole
target_class#targetRole=(value)
Note that the first letter of the role name is turned into an uppercase for the add and remove methods.
When an element is added/set on either side, this element also receives the element is is added to as a new element.
152 153 154 155 156 157 158 159 |
# File 'lib/rgen/metamodel_builder/builder_extensions.rb', line 152 def one_to_many(target_role, target_class, own_role, raw_props={}, &block) props1 = Intermediate::Reference.new(target_class, _setManyUpperBound(_ownProps(raw_props).merge({ :name=>target_role, :containment=>false}))) props2 = Intermediate::Reference.new(self, _oppositeProps(raw_props).merge({ :name=>own_role, :upperBound=>1, :containment=>false})) FeatureBlockEvaluator.eval(block, props1, props2) _build_internal(props1, props2) end |
#one_to_one(target_role, target_class, own_role, raw_props = {}, &block) ⇒ Object
Add a bidirectional one-to-one association between two classes. The class this method is called on is refered to as own_class in the following.
Instances of own_class can use ‘own_role’ to access one associated instance of type ‘target_class’. Instances of ‘target_class’ can use ‘target_role’ to access one associated instance of own_class.
This class method adds the following instance methods where ‘ownRole’ and ‘targetRole’ are to be replaced by the given role names:
own_class#ownRole
own_class#ownRole=(value)
target_class#targetRole
target_class#targetRole=(value)
When an element is set on either side, this element also receives the element is is added to as the new element.
229 230 231 232 233 234 235 236 |
# File 'lib/rgen/metamodel_builder/builder_extensions.rb', line 229 def one_to_one(target_role, target_class, own_role, raw_props={}, &block) props1 = Intermediate::Reference.new(target_class, _ownProps(raw_props).merge({ :name=>target_role, :upperBound=>1, :containment=>false})) props2 = Intermediate::Reference.new(self, _oppositeProps(raw_props).merge({ :name=>own_role, :upperBound=>1, :containment=>false})) FeatureBlockEvaluator.eval(block, props1, props2) _build_internal(props1, props2) end |