Sha256: 895c1acf93b704c53c47722962fd5435fc62e3a34b4c44f496c0916be470e606

Contents?: true

Size: 1.2 KB

Versions: 16

Compression:

Stored size: 1.2 KB

Contents

module ActiveFedora
  module Associations
    class ContainsAssociation < SingularAssociation #:nodoc:
      # Implements the reader method, e.g. foo.bar for Foo.has_one :bar
      def reader(force_reload = false)
        super || build
      end

      def find_target
        reflection.build_association(target_uri)
      end

      def target_uri
        "#{owner.uri}/#{reflection.name}"
      end

      private

      def raise_on_type_mismatch(record)
        return if record.is_a? LoadableFromJson::SolrBackedMetadataFile
        super
      end

      def replace(record)
        if record
          raise_on_type_mismatch(record)
          @updated = true
        end

        self.target = record
      end

      def new_record(method, attributes)
        record = super
        configure_datastream(record)
        record
      end

      def configure_datastream(record)
        # If you called has_metadata with a block, pass the block into the File class
        if reflection.options[:block].class == Proc
          reflection.options[:block].call(record)
        end
        if record.new_record? && reflection.options[:autocreate]
          record.datastream_will_change!
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

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