module Hydra::Works::WorkBehavior

This module provides all of the Behaviors of a Hydra::Works::Work

behavior:

1) Hydra::Works::Work can aggregate Hydra::Works::Work
2) Hydra::Works::Work can aggregate Hydra::Works::FileSet
3) Hydra::Works::Work can NOT aggregate Hydra::PCDM::Collection
4) Hydra::Works::Work can NOT aggregate Hydra::Works::Collection
5) Hydra::Works::Work can NOT aggregate Works::Object unless it is also a Hydra::Works::FileSet
6) Hydra::Works::Work can NOT contain PCDM::File
7) Hydra::Works::Work can NOT aggregate non-PCDM object
8) Hydra::Works::Work can NOT contain Hydra::Works::FileSet
9) Hydra::Works::Work can have descriptive metadata
10) Hydra::Works::Work can have access metadata

Public Class Methods

type_validator() click to toggle source
Calls superclass method
# File lib/hydra/works/models/concerns/work_behavior.rb, line 20
def self.type_validator
  Hydra::PCDM::Validators::CompositeValidator.new(
    Hydra::Works::NotCollectionValidator,
    super
  )
end

Public Instance Methods

child_file_set_ids() click to toggle source
# File lib/hydra/works/models/concerns/work_behavior.rb, line 60
def child_file_set_ids
  file_set_ids
end
child_file_sets() click to toggle source
# File lib/hydra/works/models/concerns/work_behavior.rb, line 56
def child_file_sets
  file_sets
end
child_work_ids() click to toggle source
# File lib/hydra/works/models/concerns/work_behavior.rb, line 52
def child_work_ids
  work_ids + member_work_ids
end
child_works() click to toggle source
# File lib/hydra/works/models/concerns/work_behavior.rb, line 48
def child_works
  works + member_works
end
collection?() click to toggle source

@return [Boolean] whether this instance is a Hydra::Works Collection.

# File lib/hydra/works/models/concerns/work_behavior.rb, line 109
def collection?
  false
end
file_set?() click to toggle source

@return [Boolean] whether this instance is a Hydra::Works::FileSet.

# File lib/hydra/works/models/concerns/work_behavior.rb, line 119
def file_set?
  false
end
file_set_ids() click to toggle source
# File lib/hydra/works/models/concerns/work_behavior.rb, line 94
def file_set_ids
  file_sets.map(&:id)
end
file_sets() click to toggle source
# File lib/hydra/works/models/concerns/work_behavior.rb, line 90
def file_sets
  members.select(&:file_set?)
end
in_work_ids() click to toggle source
# File lib/hydra/works/models/concerns/work_behavior.rb, line 127
def in_work_ids
  in_works.map(&:id)
end
in_works() click to toggle source
# File lib/hydra/works/models/concerns/work_behavior.rb, line 123
def in_works
  ordered_by.select { |parent| parent.class.included_modules.include?(Hydra::Works::WorkBehavior) }.to_a
end
member_of_work_ids() click to toggle source
# File lib/hydra/works/models/concerns/work_behavior.rb, line 135
def member_of_work_ids
  member_of_works.map(&:id)
end
member_of_works() click to toggle source
# File lib/hydra/works/models/concerns/work_behavior.rb, line 131
def member_of_works
  in_objects.to_a.select(&:work?)
end
member_work_ids() click to toggle source
# File lib/hydra/works/models/concerns/work_behavior.rb, line 78
def member_work_ids
  member_works.map(&:id)
end
member_works() click to toggle source
# File lib/hydra/works/models/concerns/work_behavior.rb, line 72
def member_works
  return [] if id.nil?
  member_objects = ActiveFedora::Base.where('object_ids_ssim' => id)
  member_objects.select(&:work?).to_a
end
ordered_file_set_ids() click to toggle source
# File lib/hydra/works/models/concerns/work_behavior.rb, line 103
def ordered_file_set_ids
  Deprecation.warn WorkBehavior, "ordered_file_set_ids is deprecated and will be removed in Hydra::Works 1.0. If you need order, use an interstitial work node."
  ordered_file_sets.map(&:id)
end
ordered_file_sets() click to toggle source
# File lib/hydra/works/models/concerns/work_behavior.rb, line 98
def ordered_file_sets
  Deprecation.warn WorkBehavior, "ordered_file_sets is deprecated and will be removed in Hydra::Works 1.0. If you need order, use an interstitial work node."
  ordered_members.to_a.select(&:file_set?)
end
ordered_work_ids() click to toggle source
# File lib/hydra/works/models/concerns/work_behavior.rb, line 86
def ordered_work_ids
  ordered_works.map(&:id)
end
ordered_works() click to toggle source
# File lib/hydra/works/models/concerns/work_behavior.rb, line 82
def ordered_works
  ordered_members.to_a.select(&:work?)
end
parent_collection_ids() click to toggle source
# File lib/hydra/works/models/concerns/work_behavior.rb, line 36
def parent_collection_ids
  in_collection_ids + member_of_collection_ids
end
parent_collections() click to toggle source
# File lib/hydra/works/models/concerns/work_behavior.rb, line 32
def parent_collections
  in_collections + member_of_collections
end
parent_work_ids() click to toggle source
# File lib/hydra/works/models/concerns/work_behavior.rb, line 44
def parent_work_ids
  in_work_ids + member_of_work_ids
end
parent_works() click to toggle source
# File lib/hydra/works/models/concerns/work_behavior.rb, line 40
def parent_works
  in_works + member_of_works
end
work?() click to toggle source

@return [Boolean] whether this instance is a Hydra::Works Generic Work.

# File lib/hydra/works/models/concerns/work_behavior.rb, line 114
def work?
  true
end
work_ids() click to toggle source
# File lib/hydra/works/models/concerns/work_behavior.rb, line 68
def work_ids
  works.map(&:id)
end
works() click to toggle source
# File lib/hydra/works/models/concerns/work_behavior.rb, line 64
def works
  members.select(&:work?)
end

Private Instance Methods

remove_from_parents() click to toggle source

Remove this object from parent works or collections

# File lib/hydra/works/models/concerns/work_behavior.rb, line 142
def remove_from_parents
  ordered_by.each do |parent|
    parent.ordered_members.delete(self) # Delete the list node
    parent.members.delete(self) # Delete the indirect container Proxy
    parent.save! # record the changes to the ordered members
  end
end