Class: Anchormodel::Attribute
- Inherits:
-
Object
- Object
- Anchormodel::Attribute
- Defined in:
- lib/anchormodel/attribute.rb
Overview
Metadata about an anchormodel attribute installed on a Rails model.
One instance is created per call to ModelMixin#belongs_to_anchormodel
or ModelMixin#belongs_to_anchormodels and stored in the model class's
anchormodel_attributes hash. Used internally by the AR type casters and by SimpleForm
inputs to discover what an attribute points to.
Instance Attribute Summary collapse
-
#anchormodel_class ⇒ Object
readonly
Returns the value of attribute anchormodel_class.
-
#attribute_name ⇒ Object
readonly
Returns the value of attribute attribute_name.
-
#optional ⇒ Object
readonly
Returns the value of attribute optional.
Instance Method Summary collapse
-
#initialize(model_class, attribute_name, anchormodel_class = nil, optional = false, multiple = false) ⇒ Attribute
constructor
A new instance of Attribute.
-
#multiple? ⇒ Boolean
True for
belongs_to_anchormodels(collection), false forbelongs_to_anchormodel(single).
Constructor Details
#initialize(model_class, attribute_name, anchormodel_class = nil, optional = false, multiple = false) ⇒ Attribute
Returns a new instance of Attribute.
25 26 27 28 29 30 31 |
# File 'lib/anchormodel/attribute.rb', line 25 def initialize(model_class, attribute_name, anchormodel_class = nil, optional = false, multiple = false) @model_class = model_class @attribute_name = attribute_name.to_sym @anchormodel_class = anchormodel_class @optional = optional @multiple = multiple end |
Instance Attribute Details
#anchormodel_class ⇒ Object (readonly)
Returns the value of attribute anchormodel_class.
14 15 16 |
# File 'lib/anchormodel/attribute.rb', line 14 def anchormodel_class @anchormodel_class end |
#attribute_name ⇒ Object (readonly)
Returns the value of attribute attribute_name.
10 11 12 |
# File 'lib/anchormodel/attribute.rb', line 10 def attribute_name @attribute_name end |
#optional ⇒ Object (readonly)
Returns the value of attribute optional.
18 19 20 |
# File 'lib/anchormodel/attribute.rb', line 18 def optional @optional end |
Instance Method Details
#multiple? ⇒ Boolean
Returns true for belongs_to_anchormodels (collection), false for belongs_to_anchormodel (single).
34 35 36 |
# File 'lib/anchormodel/attribute.rb', line 34 def multiple? @multiple end |