Module: Hyrax::CollectionBehavior
- Extended by:
- ActiveSupport::Concern
- Includes:
- Hydra::AccessControls::Permissions, Hydra::AccessControls::WithAccessRight, Hydra::WithDepositor, Hydra::Works::CollectionBehavior, CollectionNesting, CoreMetadata, HasRepresentative, HumanReadableType, Noid, Permissions
- Included in:
- Collection
- Defined in:
- app/models/concerns/hyrax/collection_behavior.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#add_member_objects(new_member_ids) ⇒ Object
Add member objects by adding this collection to the objects’ member_of_collection association.
-
#add_members(new_member_ids) ⇒ Object
Add members using the members association.
-
#bytes ⇒ Fixnum
Compute the sum of each file in the collection using Solr to avoid having to access Fedora.
-
#collection_type ⇒ Object
Get the collection_type when accessed.
- #collection_type=(new_collection_type) ⇒ Object
-
#member_object_ids ⇒ Object
Use this query to get the ids of the member objects (since the containment association has been flipped).
- #member_objects ⇒ Object
-
#permission_template ⇒ Hyrax::PermissionTemplate
Retrieve the permission template for this collection.
-
#reset_access_controls! ⇒ Object
Calculate and update who should have read/edit access to the collections based on who has access in PermissionTemplateAccess.
- #to_s ⇒ Object
Methods included from CollectionNesting
#find_children_of, #reindex_extent, #reindex_extent=, #update_index, #use_nested_reindexing?
Methods included from Permissions::Readable
#private?, #public?, #registered?
Methods included from Permissions::Writable
Methods included from HumanReadableType
#human_readable_type, #to_solr
Methods included from Noid
Instance Method Details
#add_member_objects(new_member_ids) ⇒ Object
Add member objects by adding this collection to the objects’ member_of_collection association.
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/models/concerns/hyrax/collection_behavior.rb', line 59 def add_member_objects(new_member_ids) Array(new_member_ids).collect do |member_id| member = ActiveFedora::Base.find(member_id) = Hyrax::MultipleMembershipChecker.new(item: member).check(collection_ids: id, include_current_members: true) if member.errors.add(:collections, ) else member.member_of_collections << self member.save! end member end end |
#add_members(new_member_ids) ⇒ Object
Add members using the members association.
53 54 55 56 |
# File 'app/models/concerns/hyrax/collection_behavior.rb', line 53 def add_members(new_member_ids) return if new_member_ids.blank? members << ActiveFedora::Base.find(new_member_ids) end |
#bytes ⇒ Fixnum
Compute the sum of each file in the collection using Solr to avoid having to access Fedora
101 102 103 104 105 106 107 108 |
# File 'app/models/concerns/hyrax/collection_behavior.rb', line 101 def bytes return 0 if member_object_ids.empty? raise "Collection must be saved to query for bytes" if new_record? # One query per member_id because Solr is not a relational database member_object_ids.collect { |work_id| size_for_work(work_id) }.sum end |
#collection_type ⇒ Object
Get the collection_type when accessed
44 45 46 |
# File 'app/models/concerns/hyrax/collection_behavior.rb', line 44 def collection_type @collection_type ||= Hyrax::CollectionType.find_by_gid!(collection_type_gid) end |
#collection_type=(new_collection_type) ⇒ Object
48 49 50 |
# File 'app/models/concerns/hyrax/collection_behavior.rb', line 48 def collection_type=(new_collection_type) self.collection_type_gid = new_collection_type.gid end |
#member_object_ids ⇒ Object
Use this query to get the ids of the member objects (since the containment association has been flipped)
112 113 114 115 |
# File 'app/models/concerns/hyrax/collection_behavior.rb', line 112 def member_object_ids return [] unless id ActiveFedora::Base.search_with_conditions("member_of_collection_ids_ssim:#{id}").map(&:id) end |
#member_objects ⇒ Object
73 74 75 |
# File 'app/models/concerns/hyrax/collection_behavior.rb', line 73 def member_objects ActiveFedora::Base.where("member_of_collection_ids_ssim:#{id}") end |
#permission_template ⇒ Hyrax::PermissionTemplate
Retrieve the permission template for this collection.
121 122 123 |
# File 'app/models/concerns/hyrax/collection_behavior.rb', line 121 def Hyrax::PermissionTemplate.find_by!(source_id: id) end |
#reset_access_controls! ⇒ Object
Calculate and update who should have read/edit access to the collections based on who has access in PermissionTemplateAccess
127 128 129 130 131 132 |
# File 'app/models/concerns/hyrax/collection_behavior.rb', line 127 def reset_access_controls! update!(edit_users: , edit_groups: , read_users: , read_groups: ( + visibility_group).uniq) end |
#to_s ⇒ Object
77 78 79 |
# File 'app/models/concerns/hyrax/collection_behavior.rb', line 77 def to_s title.present? ? title.join(' | ') : 'No Title' end |