Module: CurationConcerns::CollectionBehavior
- Extended by:
- ActiveSupport::Concern
- Includes:
- Collection, HasRepresentative, HumanReadableType, Noid, Permissions, Hydra::AccessControls::WithAccessRight
- Included in:
- Collection
- Defined in:
- app/models/concerns/curation_concerns/collection_behavior.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#bytes ⇒ Fixnum
Compute the sum of each file in the collection using Solr to avoid having to access Fedora.
- #to_s ⇒ Object
Methods included from Permissions::Readable
#private?, #public?, #registered?
Methods included from Permissions::Writable
Methods included from HumanReadableType
Methods included from Noid
Methods included from Collection
#add_member_objects, #add_members, #member_objects
Instance Method Details
#bytes ⇒ Fixnum
Compute the sum of each file in the collection using Solr to avoid having to access Fedora
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/concerns/curation_concerns/collection_behavior.rb', line 31 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| argz = { fl: "id, #{file_size_field}", fq: "{!join from=#{member_ids_field} to=id}id:#{work_id}" } files = ::FileSet.search_with_conditions({}, argz) files.reduce(0) { |sum, f| sum + f[file_size_field].to_i } end sizes.reduce(0, :+) end |
#to_s ⇒ Object
16 17 18 |
# File 'app/models/concerns/curation_concerns/collection_behavior.rb', line 16 def to_s title.present? ? title.join(' | ') : 'No Title' end |