Sha256: 0aae79e284705aa3a87f6136074630383279227dbd99a56e957fc78529ae19b3

Contents?: true

Size: 877 Bytes

Versions: 13

Compression:

Stored size: 877 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?
          file.uri = "#{uri}/#{name}" if set_uri
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

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