Sha256: a50b5caaf38b5bfe5fff053523ce16188c569ea5ef09d99401a79cd7f396b71f

Contents?: true

Size: 1.1 KB

Versions: 11

Compression:

Stored size: 1.1 KB

Contents

module ActiveFedora::Associations::Builder
  class IndirectlyContains < CollectionAssociation #:nodoc:
    self.macro = :indirectly_contains
    self.valid_options += [:has_member_relation, :is_member_of_relation, :inserted_content_relation, :foreign_key, :through]
    self.valid_options -= [:predicate]

    def build
      reflection = super
      configure_dependency
      reflection
    end

    def self.define_readers(mixin, name)
      super

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

    def validate_options
      super
      if !options[:has_member_relation] && !options[:is_member_of_relation]
        raise ArgumentError, "You must specify a predicate for #{name}"
      elsif !options[:has_member_relation].is_a?(RDF::URI) && !options[:is_member_of_relation].is_a?(RDF::URI)
        raise ArgumentError, "Predicate must be a kind of RDF::URI"
      end

      raise ArgumentError, "Missing :through option" unless options[:through]
      raise ArgumentError, "Missing :foreign_key option" unless options[:foreign_key]
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
active-fedora-9.7.3 lib/active_fedora/associations/builder/indirectly_contains.rb
active-fedora-9.7.2 lib/active_fedora/associations/builder/indirectly_contains.rb
active-fedora-9.9.1 lib/active_fedora/associations/builder/indirectly_contains.rb
active-fedora-9.9.0 lib/active_fedora/associations/builder/indirectly_contains.rb
active-fedora-9.8.2 lib/active_fedora/associations/builder/indirectly_contains.rb
active-fedora-9.8.1 lib/active_fedora/associations/builder/indirectly_contains.rb
active-fedora-9.8.0 lib/active_fedora/associations/builder/indirectly_contains.rb
active-fedora-9.7.1 lib/active_fedora/associations/builder/indirectly_contains.rb
active-fedora-9.7.0 lib/active_fedora/associations/builder/indirectly_contains.rb
active-fedora-9.6.2 lib/active_fedora/associations/builder/indirectly_contains.rb
active-fedora-9.6.1 lib/active_fedora/associations/builder/indirectly_contains.rb