Class: Upgrow::ModelSchema
Overview
The default Schema type for Basic Models. This is a specialized Schema that, in addition to attributes, supports the definition of associations.
Instance Method Summary collapse
-
#association(name) ⇒ Object
Define a Model association.
-
#association_names ⇒ Array<Symbol>
The list of association names for this Schema.
-
#initialize ⇒ ModelSchema
constructor
Sets the Model Schema’s initial state, with an empty Set of association names.
Methods inherited from Schema
Constructor Details
#initialize ⇒ ModelSchema
Sets the Model Schema’s initial state, with an empty Set of association names.
9 10 11 12 |
# File 'lib/upgrow/model_schema.rb', line 9 def initialize super @association_names = Set.new end |
Instance Method Details
#association(name) ⇒ Object
Define a Model association. An association is a special type of attribute that is optional upon initialization, but it raises an Association Not Loaded error in case its reader is called when the attribute has not been specified when the Model was instantiated.
20 21 22 |
# File 'lib/upgrow/model_schema.rb', line 20 def association(name) @association_names += [name] end |
#association_names ⇒ Array<Symbol>
The list of association names for this Schema.
27 28 29 |
# File 'lib/upgrow/model_schema.rb', line 27 def association_names @association_names.to_a end |