Sha256: da05fac500c60083a390e6747ef1f21fd9571eee06a986ca75efc7685392f979

Contents?: true

Size: 1.39 KB

Versions: 33

Compression:

Stored size: 1.39 KB

Contents

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.build(model, name, options)
      new(model, name, options).build
    end

    def initialize(model, name, options)
      super(model, name, options)
    end

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

    def writable?
      true
    end

    private

      def define_callback(callback_name)
        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

      def define_readers
        super

        name = self.name
        mixin.redefine_method("#{name.to_s.singularize}_ids") do
          association(name).ids_reader
        end
      end

      def define_writers
        super

        name = self.name
        mixin.redefine_method("#{name.to_s.singularize}_ids=") do |ids|
          association(name).ids_writer(ids)
        end
      end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
active-fedora-8.7.0 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-8.6.0 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-8.5.0 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-8.4.2 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-8.4.1 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-7.3.1 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-7.3.0 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-8.4.0 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-8.3.0 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-8.2.2 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-8.2.1 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-8.2.0 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-7.2.0 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-8.1.0 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-8.0.1 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-8.0.0 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-8.0.0.rc3 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-8.0.0.rc2 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-8.0.0.rc1 lib/active_fedora/associations/builder/collection_association.rb
active-fedora-7.1.2 lib/active_fedora/associations/builder/collection_association.rb