Class: Hyrax::PresenterFactory
- Inherits:
-
Object
- Object
- Hyrax::PresenterFactory
- Defined in:
- app/presenters/hyrax/presenter_factory.rb
Overview
Extract a SolrDocument finder class that takes a list of pids and returns/yields a ::SolrDocument for each hit in SOLR.
The given IDs are loaded from SOLR
Responsible building an Array of presenters based on IDs and presenter class given
Instance Attribute Summary collapse
-
#ids ⇒ Object
readonly
Returns the value of attribute ids.
-
#presenter_args ⇒ Object
readonly
Returns the value of attribute presenter_args.
-
#presenter_class ⇒ Object
(also: #klass)
readonly
Returns the value of attribute presenter_class.
Class Method Summary collapse
-
.build_for(ids:, presenter_class:, presenter_args: []) ⇒ Array
Presenters for the documents in order of the ids (as given).
-
.build_presenters(ids, klass, *args) ⇒ Array
deprecated
Deprecated.
use .build_for instead
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(ids:, presenter_class:, presenter_args:) ⇒ PresenterFactory
constructor
A new instance of PresenterFactory.
Constructor Details
#initialize(ids:, presenter_class:, presenter_args:) ⇒ PresenterFactory
Returns a new instance of PresenterFactory.
33 34 35 36 37 38 |
# File 'app/presenters/hyrax/presenter_factory.rb', line 33 def initialize(ids:, presenter_class:, presenter_args:) @ids = ids @presenter_class = presenter_class # In moving from splat args to named parameters, passing the parameters is a bit off. @presenter_args = presenter_args.nil? ? [nil] : presenter_args end |
Instance Attribute Details
#ids ⇒ Object (readonly)
Returns the value of attribute ids.
29 30 31 |
# File 'app/presenters/hyrax/presenter_factory.rb', line 29 def ids @ids end |
#presenter_args ⇒ Object (readonly)
Returns the value of attribute presenter_args.
29 30 31 |
# File 'app/presenters/hyrax/presenter_factory.rb', line 29 def presenter_args @presenter_args end |
#presenter_class ⇒ Object (readonly) Also known as: klass
Returns the value of attribute presenter_class.
29 30 31 |
# File 'app/presenters/hyrax/presenter_factory.rb', line 29 def presenter_class @presenter_class end |
Class Method Details
.build_for(ids:, presenter_class:, presenter_args: []) ⇒ Array
Convert to find and yield only the found SOLR documents. There is a coupling of knowledge regarding the building of the presenter class and its parameters.
We are looping through SOLR docs three times; Can this be compressed into a single loop
Returns presenters for the documents in order of the ids (as given).
14 15 16 |
# File 'app/presenters/hyrax/presenter_factory.rb', line 14 def build_for(ids:, presenter_class:, presenter_args: []) new(ids: ids, presenter_class: presenter_class, presenter_args: presenter_args).build end |
.build_presenters(ids, klass, *args) ⇒ Array
use .build_for instead
Returns presenters for the documents in order of the ids.
23 24 25 26 |
# File 'app/presenters/hyrax/presenter_factory.rb', line 23 def build_presenters(ids, klass, *args) Deprecation.warn(self, "build_presenters is deprecated and will be removed from Hyrax 3.0 (use .build_for instead)") build_for(ids: ids, presenter_class: klass, presenter_args: args) end |
Instance Method Details
#build ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'app/presenters/hyrax/presenter_factory.rb', line 40 def build return [] if ids.blank? docs = load_docs ids.map do |id| solr_doc = docs.find { |doc| doc.id == id } presenter_class.new(solr_doc, *presenter_args) if solr_doc end.compact end |