Skip to content

Commit

Permalink
Merge pull request #181 from projecthydra-labs/parent_becomes_in
Browse files Browse the repository at this point in the history
fix issue 180 - Rework association names. drop parent_ and child_
  • Loading branch information
jcoyne committed Sep 18, 2015
2 parents 274f5e0 + 89e1c80 commit bce6acc
Show file tree
Hide file tree
Showing 12 changed files with 379 additions and 253 deletions.
1 change: 1 addition & 0 deletions hydra-pcdm.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.add_dependency 'active-fedora', '>= 9.4.1'
spec.add_dependency 'activefedora-aggregation', '~> 0.4'
spec.add_dependency 'mime-types', '>= 1'

Expand Down
4 changes: 2 additions & 2 deletions lib/hydra/pcdm/collection_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module Hydra::PCDM
class CollectionIndexer < ObjectIndexer
def generate_solr_document
super.tap do |solr_doc|
solr_doc['member_ids_ssim'] = object.member_ids
solr_doc['child_collection_ids_ssim'] = object.child_collection_ids
solr_doc['member_ids_ssim'] = object.member_ids
solr_doc['collection_ids_ssim'] = object.collection_ids
end
end
end
Expand Down
17 changes: 16 additions & 1 deletion lib/hydra/pcdm/models/concerns/collection_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module CollectionBehavior
type Vocab::PCDMTerms.Collection
include ::Hydra::PCDM::PcdmBehavior

filters_association :members, as: :child_collections, condition: :pcdm_collection?
filters_association :members, as: :collections, condition: :pcdm_collection?
end

module ClassMethods
Expand All @@ -36,5 +36,20 @@ def pcdm_object?
def pcdm_collection?
true
end

def child_collections
warn '[DEPRECATION] `child_collections` is deprecated in Hydra::PCDM. Please use `collections` instead. This has a target date for removal of 10-31-2015'
collections
end

def child_collections=(new_collections)
warn '[DEPRECATION] `child_collections=` is deprecated in Hydra::PCDM. Please use `collections=` instead. This has a target date for removal of 10-31-2015'
self.collections = new_collections
end

def child_collection_ids
warn '[DEPRECATION] `child_collection_ids` is deprecated in Hydra::PCDM. Please use `collection_ids` instead. This has a target date for removal of 10-31-2015'
collection_ids
end
end
end
7 changes: 6 additions & 1 deletion lib/hydra/pcdm/models/concerns/object_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ def pcdm_collection?
false
end

def parent_objects
def in_objects
aggregated_by.select(&:pcdm_object?)
end

def parent_objects
warn '[DEPRECATION] `parent_objects` is deprecated in Hydra::PCDM. Please use `in_objects` instead. This has a target date for removal of 10-31-2015'
in_objects
end

# Returns directly contained files that have the requested RDF Type
# @param [RDF::URI] uri for the desired Type
# @example
Expand Down
38 changes: 34 additions & 4 deletions lib/hydra/pcdm/models/concerns/pcdm_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module PcdmBehavior
aggregates :members, predicate: Vocab::PCDMTerms.hasMember,
class_name: 'ActiveFedora::Base',
type_validator: type_validator
filters_association :members, as: :child_objects, condition: :pcdm_object?
filters_association :members, as: :objects, condition: :pcdm_object?
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,
Expand All @@ -22,16 +22,31 @@ def type_validator
end
end

def parents
def member_of
aggregated_by
end

def parent_collections
def parents
warn '[DEPRECATION] `parents` is deprecated in Hydra::PCDM. Please use `member_of` instead. This has a target date for removal of 10-31-2015'
member_of
end

def in_collections
aggregated_by.select(&:pcdm_collection?)
end

def parent_collections
warn '[DEPRECATION] `parent_collections` is deprecated in Hydra::PCDM. Please use `in_collections` instead. This has a target date for removal of 10-31-2015'
in_collections
end

def in_collection_ids
in_collections.map(&:id)
end

def parent_collection_ids
parent_collections.map(&:id)
warn '[DEPRECATION] `parent_collection_ids` is deprecated in Hydra::PCDM. Please use `in_collection_ids` instead. This has a target date for removal of 10-31-2015'
in_collection_ids
end

def ancestor?(record)
Expand All @@ -41,5 +56,20 @@ def ancestor?(record)
def ancestor_checker
@ancestor_checker ||= ::Hydra::PCDM::AncestorChecker.new(self)
end

def child_objects
warn '[DEPRECATION] `child_objects` is deprecated in Hydra::PCDM. Please use `objects` instead. This has a target date for removal of 10-31-2015'
objects
end

def child_objects=(new_objects)
warn '[DEPRECATION] `child_objects=` is deprecated in Hydra::PCDM. Please use `objects=` instead. This has a target date for removal of 10-31-2015'
self.objects = new_objects
end

def child_object_ids
warn '[DEPRECATION] `child_object_ids` is deprecated in Hydra::PCDM. Please use `object_ids` instead. This has a target date for removal of 10-31-2015'
object_ids
end
end
end
2 changes: 1 addition & 1 deletion lib/hydra/pcdm/object_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Hydra::PCDM
class ObjectIndexer < ActiveFedora::IndexingService
def generate_solr_document
super.tap do |solr_doc|
solr_doc['child_object_ids_ssim'] = object.child_object_ids
solr_doc['object_ids_ssim'] = object.object_ids
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/hydra/pcdm/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Hydra
module PCDM
VERSION = '0.1.0'
VERSION = '0.2.0'
end
end
12 changes: 6 additions & 6 deletions spec/hydra/pcdm/collection_indexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

describe Hydra::PCDM::CollectionIndexer do
let(:collection) { Hydra::PCDM::Collection.new }
let(:child_collection_ids) { %w(123 456) }
let(:child_object_ids) { ['789'] }
let(:collection_ids) { %w(123 456) }
let(:object_ids) { ['789'] }
let(:member_ids) { %w(123 456 789) }
let(:indexer) { described_class.new(collection) }

before do
allow(collection).to receive(:child_collection_ids).and_return(child_collection_ids)
allow(collection).to receive(:child_object_ids).and_return(child_object_ids)
allow(collection).to receive(:collection_ids).and_return(collection_ids)
allow(collection).to receive(:object_ids).and_return(object_ids)
allow(collection).to receive(:member_ids).and_return(member_ids)
end

describe '#generate_solr_document' do
subject { indexer.generate_solr_document }

it 'has fields' do
expect(subject['child_collection_ids_ssim']).to eq %w(123 456)
expect(subject['child_object_ids_ssim']).to eq ['789']
expect(subject['collection_ids_ssim']).to eq %w(123 456)
expect(subject['object_ids_ssim']).to eq ['789']
expect(subject['member_ids_ssim']).to eq %w(123 456 789)
end
end
Expand Down
Loading

0 comments on commit bce6acc

Please sign in to comment.