Skip to content

Commit

Permalink
Merge pull request #212 from projecthydra-labs/parent_becomes_in
Browse files Browse the repository at this point in the history
Fix 211 - Rework association names. drop parent_ and child_
  • Loading branch information
jcoyne committed Sep 18, 2015
2 parents bf57c69 + 393aa95 commit 21a4c02
Show file tree
Hide file tree
Showing 13 changed files with 341 additions and 211 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ gemspec
gem 'slop', '~> 3.6' # For byebug

group :development, :test do
gem 'hydra-pcdm', github: 'projecthydra-labs/hydra-pcdm', branch: 'namespace_vocabs'
gem 'rubocop', require: false
gem 'rubocop-rspec', require: false
gem 'pry' unless ENV['CI']
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ collection = Collection.create
book = BookWork.create
page = Page.create

collection.child_generic_works << book
collection.generic_works << book
collection.save
book.generic_files << page
book.save
Expand Down
30 changes: 15 additions & 15 deletions hydra-works.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'hydra/works/version'

Gem::Specification.new do |spec|
spec.name = "hydra-works"
spec.name = 'hydra-works'
spec.version = Hydra::Works::VERSION
spec.authors = ["Justin Coyne"]
spec.email = ["[email protected]"]
spec.authors = ['Justin Coyne']
spec.email = ['[email protected]']
spec.summary = %q{Fundamental repository data model for hydra}
spec.description = %q{Using this data model should enable easy collaboration amongst hydra projects.}
spec.homepage = ""
spec.license = "APACHE2"
spec.homepage = ''
spec.license = 'APACHE2'

spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]
spec.require_paths = ['lib']

spec.add_dependency "hydra-pcdm", "~> 0.1"
spec.add_dependency "hydra-derivatives", "~> 2.0"
spec.add_dependency "activefedora-aggregation", "~> 0.4"
spec.add_dependency "active-fedora", "~> 9.2"
spec.add_dependency 'hydra-pcdm', '~> 0.2'
spec.add_dependency 'hydra-derivatives', '~> 2.0'
spec.add_dependency 'active-fedora', '>= 9.4.1'
spec.add_dependency 'activefedora-aggregation', '~> 0.4'

spec.add_development_dependency "bundler", "~> 1.7"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec-rails", "~> 3.1"
spec.add_development_dependency "engine_cart", "~> 0"
spec.add_development_dependency "sqlite3"
spec.add_development_dependency 'bundler', '~> 1.7'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec-rails', '~> 3.1'
spec.add_development_dependency 'engine_cart', '~> 0'
spec.add_development_dependency 'sqlite3'
spec.add_development_dependency 'jettywrapper', '>= 2.0.0'
spec.add_development_dependency 'coveralls'
spec.add_development_dependency 'rspec'
Expand Down
16 changes: 13 additions & 3 deletions lib/hydra/works/models/concerns/block_child_objects.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
module Hydra::Works
# Do not allow aggregation of child objects
module BlockChildObjects
def child_objects=(_objects)
fail StandardError, "method `child_objects=' not allowed for #{self}"
def objects=(_objects)
fail StandardError, "method `objects=' not allowed for #{self}"
end

def objects
fail StandardError, "method `objects' not allowed for #{self}"
end

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

def child_objects
fail StandardError, "method `child_objects' not allowed for #{self}"
warn '[DEPRECATION] `child_objects` is deprecated in Hydra::Works. Please use `objects` instead. This has a target date for removal of 10-31-2015'
objects
end
end
end
48 changes: 44 additions & 4 deletions lib/hydra/works/models/concerns/collection_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ module CollectionBehavior
type [Hydra::PCDM::Vocab::PCDMTerms.Collection, Vocab::WorksTerms.Collection]
include Hydra::Works::BlockChildObjects

filters_association :members, as: :child_collections, condition: :works_collection?
filters_association :members, as: :child_generic_works, condition: :works_generic_work?
filters_association :members, as: :collections, condition: :works_collection?
filters_association :members, as: :generic_works, condition: :works_generic_work?
end

# @return [Boolean] whether this instance is a Hydra::Works Collection.
Expand All @@ -40,12 +40,52 @@ def works_generic_file?
false
end

def parents
def member_of
aggregated_by
end

def parent_collections
def parents
warn '[DEPRECATION] `parents` is deprecated in Hydra::Works. 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 { |parent| parent.class.included_modules.include?(Hydra::Works::CollectionBehavior) }
end

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

def child_collections
warn '[DEPRECATION] `child_collections` is deprecated in Hydra::Works. 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::Works. 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::Works. Please use `collection_ids` instead. This has a target date for removal of 10-31-2015'
collection_ids
end

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

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

def child_generic_work_ids
warn '[DEPRECATION] `child_generic_work_ids` is deprecated in Hydra::Works. Please use `generic_work_ids` instead. This has a target date for removal of 10-31-2015'
generic_work_ids
end
end
end
14 changes: 12 additions & 2 deletions lib/hydra/works/models/concerns/generic_file_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,22 @@ def works_generic_file?
true
end

def parents
def member_of
aggregated_by
end

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

def in_generic_works
aggregated_by.select { |parent| parent.class.included_modules.include?(Hydra::Works::GenericWorkBehavior) }
end

def generic_works
warn '[DEPRECATION] `generic_works` is deprecated in Hydra::Works. Please use `in_generic_works` instead. This has a target date for removal of 10-31-2015'
in_generic_works
end
end
end
38 changes: 34 additions & 4 deletions lib/hydra/works/models/concerns/generic_work_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module GenericWorkBehavior
type [Hydra::PCDM::Vocab::PCDMTerms.Object, Vocab::WorksTerms.GenericWork]
include Hydra::Works::BlockChildObjects

filters_association :members, as: :child_generic_works, condition: :works_generic_work?
filters_association :members, as: :generic_works, condition: :works_generic_work?
filters_association :members, as: :generic_files, condition: :works_generic_file?
end

Expand All @@ -39,16 +39,46 @@ def works_generic_file?
false
end

def parents
def member_of
aggregated_by
end

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

def in_generic_works
aggregated_by.select { |parent| parent.class.included_modules.include?(Hydra::Works::GenericWorkBehavior) }
end

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

def in_collections
aggregated_by.select { |parent| parent.class.included_modules.include?(Hydra::Works::CollectionBehavior) }
end

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

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

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

def child_generic_work_ids
warn '[DEPRECATION] `child_generic_work_ids` is deprecated in Hydra::Works. Please use `generic_work_ids` instead. This has a target date for removal of 10-31-2015'
generic_work_ids
end
end
end
2 changes: 1 addition & 1 deletion lib/hydra/works/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Hydra
module Works
VERSION = '0.1.0'
VERSION = '0.2.0'
end
end
Loading

0 comments on commit 21a4c02

Please sign in to comment.