lib/hydra/pcdm/models/concerns/object_behavior.rb in hydra-pcdm-0.0.1 vs lib/hydra/pcdm/models/concerns/object_behavior.rb in hydra-pcdm-0.1.0

- old
+ new

@@ -1,7 +1,5 @@ -require 'active_fedora/aggregation' - module Hydra::PCDM # behavior: # 1) Hydra::PCDM::Object can aggregate (pcdm:hasMember) Hydra::PCDM::Object # 2) Hydra::PCDM::Object can aggregate (ore:aggregates) Hydra::PCDM::Object (Object related to the Object) @@ -14,60 +12,38 @@ module ObjectBehavior extend ActiveSupport::Concern included do type RDFVocabularies::PCDMTerms.Object + include ::Hydra::PCDM::PcdmBehavior - aggregates :members, predicate: RDFVocabularies::PCDMTerms.hasMember, - class_name: "ActiveFedora::Base" - - 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 - directly_contains :files, has_member_relation: RDFVocabularies::PCDMTerms.hasFile, class_name: "Hydra::PCDM::File" - end module ClassMethods def indexer Hydra::PCDM::ObjectIndexer end - end - def objects= objects - raise ArgumentError, "each object must be a pcdm object" unless objects.all? { |o| Hydra::PCDM.object? o } - raise ArgumentError, "an object can't be an ancestor of itself" if object_ancestor?(objects) - self.members = objects + def type_validator + @type_validator ||= Validators::PCDMObjectValidator + end end - def objects - members.to_a.select { |m| Hydra::PCDM.object? m } + # @return [Boolean] whether this instance is a PCDM Object. + def pcdm_object? + true end - def object_ancestor? objects - objects.each do |check| - return true if check.id == self.id - return true if ancestor?(check) - end + # @return [Boolean] whether this instance is a PCDM Collection. + def pcdm_collection? false end - def ancestor? object - return true if object.id == self.id - return false if object.objects.empty? - current_objects = object.objects - next_batch = [] - while !current_objects.empty? do - current_objects.each do |c| - return true if c.id == self.id - next_batch += c.objects - end - current_objects = next_batch - end - false + def parent_objects + aggregated_by.select(&:pcdm_object?) end def contains= files # check that file is an instance of Hydra::PCDM::File raise ArgumentError, "each file must be a pcdm file" unless @@ -79,11 +55,11 @@ # @param [RDF::URI] uri for the desired Type # @example # filter_files_by_type(::RDF::URI("http://pcdm.org/ExtractedText")) def filter_files_by_type uri self.files.reject do |file| - file.metadata_node.query(predicate: RDF.type, object: uri).map(&:object).empty? + !file.metadata_node.type.include?(uri) end end # Finds or Initializes directly contained file with the requested RDF Type # @param [RDF::URI] uri for the desired Type @@ -96,9 +72,8 @@ Hydra::PCDM::AddTypeToFile.call(file, uri) else return matching_files.first end end - end end