Sha256: fef500741ff7358718393143ffa41fd7c4503ff6a7a5e8d3c4bf70acb1c17b1c

Contents?: true

Size: 1.76 KB

Versions: 7

Compression:

Stored size: 1.76 KB

Contents

module Hydra::PCDM
  module PcdmBehavior
    extend ActiveSupport::Concern
    included do
      ordered_aggregation :members,
                          has_member_relation: Vocab::PCDMTerms.hasMember,
                          class_name: 'ActiveFedora::Base',
                          type_validator: type_validator,
                          through: :list_source
      indirectly_contains :related_objects, has_member_relation: RDF::Vocab::ORE.aggregates,
                                            inserted_content_relation: RDF::Vocab::ORE.proxyFor, class_name: 'ActiveFedora::Base',
                                            through: 'ActiveFedora::Aggregation::Proxy', foreign_key: :target,
                                            type_validator: Validators::PCDMObjectValidator
    end

    module ClassMethods
      def type_validator
        @type_validator ||= Validators::CompositeValidator.new(
          super,
          Validators::PCDMValidator,
          Validators::AncestorValidator
        )
      end
    end

    def member_of
      return [] if id.nil?
      ActiveFedora::Base.where(Config.indexing_member_ids_key => id)
    end

    def ordered_member_ids
      ordered_member_proxies.map(&:target_id)
    end

    def objects
      members.select(&:pcdm_object?)
    end

    def object_ids
      objects.map(&:id)
    end

    def ordered_objects
      ordered_members.to_a.select(&:pcdm_object?)
    end

    def ordered_object_ids
      ordered_objects.map(&:id)
    end

    def in_collections
      member_of.select(&:pcdm_collection?).to_a
    end

    def in_collection_ids
      in_collections.map(&:id)
    end

    def ancestor?(potential_ancestor)
      ::Hydra::PCDM::AncestorChecker.former_is_ancestor_of_latter?(potential_ancestor, self)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hydra-pcdm-0.9.0 lib/hydra/pcdm/models/concerns/pcdm_behavior.rb
hydra-pcdm-0.8.2 lib/hydra/pcdm/models/concerns/pcdm_behavior.rb
hydra-pcdm-0.8.1 lib/hydra/pcdm/models/concerns/pcdm_behavior.rb
hydra-pcdm-0.8.0 lib/hydra/pcdm/models/concerns/pcdm_behavior.rb
hydra-pcdm-0.8.0.beta1 lib/hydra/pcdm/models/concerns/pcdm_behavior.rb
hydra-pcdm-0.7.0 lib/hydra/pcdm/models/concerns/pcdm_behavior.rb
hydra-pcdm-0.6.0 lib/hydra/pcdm/models/concerns/pcdm_behavior.rb