Sha256: 94fabfa5861016f646c916553f1c56747d79b95a3f9bfa64c564fea4930767ef

Contents?: true

Size: 1002 Bytes

Versions: 19

Compression:

Stored size: 1002 Bytes

Contents

module ActiveFedora::Associations::Builder
  class Contains < SingularAssociation #:nodoc:
    self.macro = :contains
    self.valid_options += [:autocreate, :block]

    def initialize(model, name, options)
      super
      options[:class_name] = 'ActiveFedora::File' if options[:class_name].blank?
    end

    def validate_options
      super
      if options[:class_name] && !options[:class_name].is_a?(String)
        raise ArgumentError, ":class_name must be a string for contains '#{name}'" unless options[:class_name].is_a? String
      end
    end

    def self.define_readers(mixin, name)
      mixin.send(:define_method, name) do |*params|
        association(name).reader(*params).tap do |file|
          set_uri = uri.kind_of?(RDF::URI) ? uri.value.present? : uri.present?
          if set_uri
            file_uri = "#{uri}/#{name}"
            file.uri = file_uri
            file.exists! if contains_assertions.include?(file_uri)
          end
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
active-fedora-9.0.8 lib/active_fedora/associations/builder/contains.rb
active-fedora-9.4.3 lib/active_fedora/associations/builder/contains.rb
active-fedora-9.4.2 lib/active_fedora/associations/builder/contains.rb
active-fedora-9.4.1 lib/active_fedora/associations/builder/contains.rb
active-fedora-9.4.0 lib/active_fedora/associations/builder/contains.rb
active-fedora-9.3.0 lib/active_fedora/associations/builder/contains.rb
active-fedora-9.2.1 lib/active_fedora/associations/builder/contains.rb
active-fedora-9.2.0 lib/active_fedora/associations/builder/contains.rb
active-fedora-9.2.0.rc2 lib/active_fedora/associations/builder/contains.rb
active-fedora-9.2.0.rc1 lib/active_fedora/associations/builder/contains.rb
active-fedora-9.1.2 lib/active_fedora/associations/builder/contains.rb
active-fedora-9.1.1 lib/active_fedora/associations/builder/contains.rb
active-fedora-9.1.0 lib/active_fedora/associations/builder/contains.rb
active-fedora-9.1.0.rc1 lib/active_fedora/associations/builder/contains.rb
active-fedora-9.0.6 lib/active_fedora/associations/builder/contains.rb
active-fedora-9.0.5 lib/active_fedora/associations/builder/contains.rb
active-fedora-9.0.4 lib/active_fedora/associations/builder/contains.rb
active-fedora-9.0.3 lib/active_fedora/associations/builder/contains.rb
active-fedora-9.0.2 lib/active_fedora/associations/builder/contains.rb