Module: CurationConcerns::CollectionBehavior
- Extended by:
- ActiveSupport::Concern
- Includes:
- HasRepresentative, HumanReadableType, Noid, Permissions, Hydra::AccessControls::WithAccessRight, Hydra::Collection
- Included in:
- Collection
- Defined in:
- app/models/concerns/curation_concerns/collection_behavior.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #add_member(collectible) ⇒ Object
-
#bytes ⇒ Fixnum
Compute the sum of each file in the collection using Solr to avoid having to access Fedora.
- #can_be_member_of_collection?(collection) ⇒ Boolean
- #to_s ⇒ Object
Methods included from Permissions::Readable
#private?, #public?, #registered?
Methods included from Permissions::Writable
#paranoid_edit_permissions, #paranoid_permissions
Methods included from HumanReadableType
#human_readable_type, #to_solr
Methods included from Noid
Instance Method Details
#add_member(collectible) ⇒ Object
16 17 18 19 20 |
# File 'app/models/concerns/curation_concerns/collection_behavior.rb', line 16 def add_member(collectible) return unless can_add_to_members?(collectible) members << collectible save end |
#bytes ⇒ Fixnum
Compute the sum of each file in the collection using Solr to avoid having to access Fedora
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/models/concerns/curation_concerns/collection_behavior.rb', line 41 def bytes return 0 if member_ids.count == 0 raise "Collection must be saved to query for bytes" if new_record? # One query per member_id because Solr is not a relational database sizes = member_ids.collect do |work_id| query = ActiveFedora::SolrQueryBuilder.construct_query_for_rel(has_model: ::FileSet.to_class_uri) argz = { fl: "id, #{file_size_field}", fq: "{!join from=#{member_ids_field} to=id}id:#{work_id}" } files = ActiveFedora::SolrService.query(query, argz) files.reduce(0) { |sum, f| sum + f[file_size_field].to_i } end sizes.reduce(0, :+) end |
#can_be_member_of_collection?(collection) ⇒ Boolean
26 27 28 |
# File 'app/models/concerns/curation_concerns/collection_behavior.rb', line 26 def can_be_member_of_collection?(collection) collection != self end |
#to_s ⇒ Object
22 23 24 |
# File 'app/models/concerns/curation_concerns/collection_behavior.rb', line 22 def to_s title.present? ? title : 'No Title' end |