Class: Reality::Model::ModelElement
- Inherits:
-
Object
- Object
- Reality::Model::ModelElement
- Defined in:
- lib/reality/model/model_element.rb
Overview
A descriptor describing a base type in the system model.
Instance Attribute Summary collapse
-
#access_method ⇒ Object
readonly
Returns the value of attribute access_method.
-
#container_key ⇒ Object
readonly
Returns the value of attribute container_key.
-
#id_method ⇒ Object
readonly
Returns the value of attribute id_method.
-
#inverse_access_method ⇒ Object
readonly
Returns the value of attribute inverse_access_method.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#model_classname ⇒ Object
readonly
Returns the value of attribute model_classname.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
Instance Method Summary collapse
- #custom_initialize? ⇒ Boolean
-
#initialize(repository, key, container_key, options) {|_self| ... } ⇒ ModelElement
constructor
A new instance of ModelElement.
- #model ⇒ Object
- #qualified_key ⇒ Object
Constructor Details
#initialize(repository, key, container_key, options) {|_self| ... } ⇒ ModelElement
Returns a new instance of ModelElement.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/reality/model/model_element.rb', line 20 def initialize(repository, key, container_key, ) Reality::Options.check(, [:model_classname, :custom_initialize, :id_method, :access_method, :inverse_access_method], Reality::Model, 'create model element') @repository = repository @key = key.to_sym @model_classname = ([:model_classname] || Reality::Naming.pascal_case(key)).to_sym @custom_initialize = [:custom_initialize].nil? ? false : !![:custom_initialize] @id_method = ([:id_method] || repository.default_id_method).to_sym @access_method = ([:access_method] || Reality::Naming.pluralize(@key)).to_sym @inverse_access_method = ([:inverse_access_method] || @key).to_sym @container_key = container_key.nil? ? nil : container_key.to_sym { :key => @key, :id_method => @id_method, :access_method => @access_method, :inverse_access_method => @inverse_access_method, }.each_pair do |attribute_name, value| unless Reality::Naming.underscore?(value) Reality::Model.error("Model Element '#{qualified_key}' has a #{attribute_name} '#{value}' that does not use the underscore naming pattern (i.e. The #{attribute_name} should be '#{Reality::Naming.underscore(value)}').") end end unless Reality::Naming.pascal_case?(@model_classname) Reality::Model.error("Model Element '#{qualified_key}' has a model_classname '#{@model_classname}' that does not use the pascal case naming pattern (i.e. The model_classname should be '#{Reality::Naming.pascal_case(@model_classname)}').") end if @container_key && !repository.model_element_by_key?(@container_key) Reality::Model.error("Model Element '#{qualified_key}' defines container as '#{@container_key}' but no such model element exists.") end @repository.send(:register_model_element, self) yield self if block_given? end |
Instance Attribute Details
#access_method ⇒ Object (readonly)
Returns the value of attribute access_method.
62 63 64 |
# File 'lib/reality/model/model_element.rb', line 62 def access_method @access_method end |
#container_key ⇒ Object (readonly)
Returns the value of attribute container_key.
59 60 61 |
# File 'lib/reality/model/model_element.rb', line 59 def container_key @container_key end |
#id_method ⇒ Object (readonly)
Returns the value of attribute id_method.
61 62 63 |
# File 'lib/reality/model/model_element.rb', line 61 def id_method @id_method end |
#inverse_access_method ⇒ Object (readonly)
Returns the value of attribute inverse_access_method.
63 64 65 |
# File 'lib/reality/model/model_element.rb', line 63 def inverse_access_method @inverse_access_method end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
58 59 60 |
# File 'lib/reality/model/model_element.rb', line 58 def key @key end |
#model_classname ⇒ Object (readonly)
Returns the value of attribute model_classname.
60 61 62 |
# File 'lib/reality/model/model_element.rb', line 60 def model_classname @model_classname end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
57 58 59 |
# File 'lib/reality/model/model_element.rb', line 57 def repository @repository end |
Instance Method Details
#custom_initialize? ⇒ Boolean
65 66 67 |
# File 'lib/reality/model/model_element.rb', line 65 def custom_initialize? @custom_initialize end |
#model ⇒ Object
73 74 75 |
# File 'lib/reality/model/model_element.rb', line 73 def model self.repository.model_container.const_get(self.model_classname) end |
#qualified_key ⇒ Object
69 70 71 |
# File 'lib/reality/model/model_element.rb', line 69 def qualified_key "#{repository.key}.#{self.key}" end |