Class: Upgrow::ModelSchema

Inherits:
Schema
  • Object
show all
Defined in:
lib/upgrow/model_schema.rb

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

Methods inherited from Schema

#attribute, #attribute_names

Constructor Details

#initializeModelSchema

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.

Parameters:

  • name (Symbol)

    the name of the association.



20
21
22
# File 'lib/upgrow/model_schema.rb', line 20

def association(name)
  @association_names += [name]
end

#association_namesArray<Symbol>

The list of association names for this Schema.

Returns:

  • (Array<Symbol>)

    the list of association names.



27
28
29
# File 'lib/upgrow/model_schema.rb', line 27

def association_names
  @association_names.to_a
end