Class: Hyrax::CollectionSizeService Deprecated

Inherits:
Object
  • Object
show all
Includes:
Blacklight::Configurable, Blacklight::SearchHelper
Defined in:
app/services/hyrax/collection_size_service.rb

Overview

Deprecated.

This class is broken for base Hyrax applications. Current users should call with extreme caution and consider a local implementation as an alternative.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection) ⇒ CollectionSizeService

Returns a new instance of CollectionSizeService.



20
21
22
23
24
25
26
27
28
29
# File 'app/services/hyrax/collection_size_service.rb', line 20

def initialize(collection)
  Deprecation
    .warn(self, 'CollectionSizeService has been deprecated for removal in ' \
                'Hyrax 3.0. This class is broken for base Hyrax ' \
                'applications. Current users should call with extreme ' \
                'caution and consider a local implementation as an ' \
                'alternative.')

  @collection = collection
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



12
13
14
# File 'app/services/hyrax/collection_size_service.rb', line 12

def collection
  @collection
end

Class Method Details

.run(collection) ⇒ Object



16
17
18
# File 'app/services/hyrax/collection_size_service.rb', line 16

def self.run(collection)
  new(collection).collection_size
end

Instance Method Details

#collection_search_builderObject



40
41
42
# File 'app/services/hyrax/collection_size_service.rb', line 40

def collection_search_builder
  @collection_search_builder ||= MemberWithFilesSearchBuilder.new([:include_contained_files, :add_paging_to_solr], self)
end

#collection_sizeObject



31
32
33
34
35
36
37
38
# File 'app/services/hyrax/collection_size_service.rb', line 31

def collection_size
  query = collection_search_builder.with('id' => collection.id).rows(max_collection_size).merge(fl: [size_field])
  resp = repository.search(query)
  field_name = size_field
  resp.documents.reduce(0) do |total, doc|
    total + (doc[field_name].blank? ? 0 : doc[field_name][0].to_f)
  end
end

#max_collection_sizeObject



48
49
50
# File 'app/services/hyrax/collection_size_service.rb', line 48

def max_collection_size
  1000
end

#size_fieldObject



44
45
46
# File 'app/services/hyrax/collection_size_service.rb', line 44

def size_field
  Solrizer.solr_name(:file_size, :symbol)
end