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
Direct Known Subclasses
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
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).
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.
22 23 24 25 26 27 |
# File 'app/presenters/hyrax/presenter_factory.rb', line 22 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.
20 21 22 |
# File 'app/presenters/hyrax/presenter_factory.rb', line 20 def ids @ids end |
#presenter_args ⇒ Object (readonly)
Returns the value of attribute presenter_args.
20 21 22 |
# File 'app/presenters/hyrax/presenter_factory.rb', line 20 def presenter_args @presenter_args end |
#presenter_class ⇒ Object (readonly)
Returns the value of attribute presenter_class.
20 21 22 |
# File 'app/presenters/hyrax/presenter_factory.rb', line 20 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).
15 16 17 |
# File 'app/presenters/hyrax/presenter_factory.rb', line 15 def build_for(ids:, presenter_class:, presenter_args: []) new(ids: ids, presenter_class: presenter_class, presenter_args: presenter_args).build end |
Instance Method Details
#build ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'app/presenters/hyrax/presenter_factory.rb', line 29 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 |