Class: ActiveFedora::Associations::Builder::CollectionAssociation

Inherits:
Association
  • Object
show all
Defined in:
lib/active_fedora/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

Attributes inherited from Association

#mixin, #model, #name, #options

Class Method Summary collapse

Methods inherited from Association

build, #build, #configure_dependency, define_accessors, define_readers, define_writers, #initialize, #predicate, #translate_property_to_predicate, #validate_options

Constructor Details

This class inherits a constructor from ActiveFedora::Associations::Builder::Association

Class Method Details

.define_callback(model, callback_name, name, options) ⇒ Object


16
17
18
19
20
21
22
# File 'lib/active_fedora/associations/builder/collection_association.rb', line 16

def self.define_callback(model, callback_name, name, options)
  full_callback_name = "#{callback_name}_for_#{name}"

  # TODO : why do i need method_defined? I think its because of the inheritance chain
  model.class_attribute full_callback_name.to_sym unless model.method_defined?(full_callback_name)
  model.send("#{full_callback_name}=", Array(options[callback_name.to_sym]))
end

.define_callbacks(model, reflection) ⇒ Object


10
11
12
13
14
# File 'lib/active_fedora/associations/builder/collection_association.rb', line 10

def self.define_callbacks(model, reflection)
  name = reflection.name
  options = reflection.options
  CALLBACKS.each { |callback_name| define_callback(model, callback_name, name, options) }
end