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.8 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.7.0 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.6.2 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.6.1 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.5.0 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.4.3 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.4.2 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.4.1 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.4.0 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.3.0 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.2.1 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.2.0 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.2.0.rc2 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.2.0.rc1 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.1.2 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.1.1 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.1.0 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.1.0.rc1 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.0.6 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.0.5 lib/active_fedora/associations/builder/collection_association.rb