Sha256: 6247befd4eac4dfb0bc5255ac9ceb434fcc4d6c5ffe850ac5449741e14eb9d09

Contents?: true

Size: 936 Bytes

Versions: 36

Compression:

Stored size: 936 Bytes

Contents

require 'active_fedora/associations'
module ActiveFedora::Associations::Builder
  class CollectionAssociation < Association #:nodoc:
    CALLBACKS = [:before_add, :after_add, :before_remove, :after_remove]

    self.valid_options += [
      :before_add, :after_add, :before_remove, :after_remove
    ]

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

    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
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
active-fedora-9.0.4 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.0.3 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.0.2 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.0.1 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.0.0 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.0.0.rc3 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.0.0.rc2 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.0.0.rc1 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.0.0.beta8 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.0.0.beta7 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.0.0.beta6 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.0.0.beta5 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.0.0.beta4 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.0.0.beta3 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.0.0.beta2 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.0.0.beta1 lib/active_fedora/associations/builder/collection_association.rb