Class: Anchormodel::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/anchormodel/attribute.rb

Overview

This class holds all information related to a Rails model pointing to an Anchormodel. It is instanciated when ModelMixin#belongs_to_anchormodel is used.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_class, attribute_name, anchormodel_class = nil, optional = false, multiple = false) ⇒ Attribute

Returns a new instance of Attribute.

Parameters:

  • model_class (ActiveRecord::Base)

    The Rails model where ModelMixin#belongs_to_anchormodel is used

  • attribute_name (String, Symbol)

    The name and database column of the attribute

  • anchormodel_class (Class) (defaults to: nil)

    Class of the Anchormodel (omit if attribute :foo_bar holds an FooBar)

  • optional (Boolean) (defaults to: false)

    If true, a presence validation is added to the model.

  • multiple (Boolean) (defaults to: false)

    If true, this attribute holds multiple anchormodels.



14
15
16
17
18
19
20
# File 'lib/anchormodel/attribute.rb', line 14

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_classObject (readonly)



6
7
8
# File 'lib/anchormodel/attribute.rb', line 6

def anchormodel_class
  @anchormodel_class
end

#attribute_nameObject (readonly)



5
6
7
# File 'lib/anchormodel/attribute.rb', line 5

def attribute_name
  @attribute_name
end

#optionalObject (readonly)



7
8
9
# File 'lib/anchormodel/attribute.rb', line 7

def optional
  @optional
end

Instance Method Details

#multiple?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/anchormodel/attribute.rb', line 22

def multiple?
  @multiple
end