Class: ActiveRecord::Associations::Builder::CollectionAssociation

Inherits:
Association show all
Defined in:
activerecord/lib/active_record/associations/builder/collection_association.rb

Overview

:nodoc:

Direct Known Subclasses

HasAndBelongsToMany, HasMany

Constant Summary collapse

CALLBACKS =
[:before_add, :after_add, :before_remove, :after_remove]

Instance Attribute Summary collapse

Attributes inherited from Association

#model, #name, #options, #reflection

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, name, options, &extension) ⇒ CollectionAssociation

Returns a new instance of CollectionAssociation.



16
17
18
19
# File 'activerecord/lib/active_record/associations/builder/collection_association.rb', line 16

def initialize(model, name, options, &extension)
  super(model, name, options)
  @block_extension = extension
end

Instance Attribute Details

#block_extensionObject (readonly)

Returns the value of attribute block_extension



10
11
12
# File 'activerecord/lib/active_record/associations/builder/collection_association.rb', line 10

def block_extension
  @block_extension
end

Class Method Details

.build(model, name, options, &extension) ⇒ Object



12
13
14
# File 'activerecord/lib/active_record/associations/builder/collection_association.rb', line 12

def self.build(model, name, options, &extension)
  new(model, name, options, &extension).build
end

Instance Method Details

#buildObject



21
22
23
24
25
26
# File 'activerecord/lib/active_record/associations/builder/collection_association.rb', line 21

def build
  wrap_block_extension
  reflection = super
  CALLBACKS.each { |callback_name| define_callback(callback_name) }
  reflection
end

#writable?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'activerecord/lib/active_record/associations/builder/collection_association.rb', line 28

def writable?
  true
end