Sha256: 08744411e6358f35b5630c7a3fe87592e0d7e0ca381a75e373e3cf0ba4ec820a

Contents?: true

Size: 928 Bytes

Versions: 2

Compression:

Stored size: 928 Bytes

Contents

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

    def self.valid_options(options)
      super + CALLBACKS
    end

    def self.define_callbacks(model, reflection)
      name = reflection.name
      options = reflection.options
      super
      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

2 entries across 2 versions & 1 rubygems

Version Path
active-fedora-9.10.0.pre2 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-9.10.0.pre1 lib/active_fedora/associations/builder/collection_association.rb