Class: Hyrax::PcdmMemberPresenterFactory
- Inherits:
-
Object
- Object
- Hyrax::PcdmMemberPresenterFactory
- Defined in:
- app/presenters/hyrax/pcdm_member_presenter_factory.rb
Overview
constructs presenters for the pcdm:members of an Object, omitting those not readable by a provided Ability
.
this implementation builds the presenters without recourse to the request context and ActiveFedora-specific index structures (i.e. no ‘list_source` or `proxy_in_ssi`).
Instance Attribute Summary collapse
-
#ability ⇒ Object
readonly
Returns the value of attribute ability.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
- #file_set_presenters ⇒ Array<FileSetPresenter, WorkShowPresenter>, Enumerator<FileSetPresenter>
-
#initialize(object, ability, _request = nil) ⇒ PcdmMemberPresenterFactory
constructor
A new instance of PcdmMemberPresenterFactory.
- #member_presenters(ids = object.member_ids) ⇒ Object
- #ordered_ids ⇒ Array<#to_s>
- #presenter_for(document:, ability:) ⇒ Object
- #work_presenters ⇒ Array<WorkShowPresenter>
Constructor Details
#initialize(object, ability, _request = nil) ⇒ PcdmMemberPresenterFactory
Returns a new instance of PcdmMemberPresenterFactory.
22 23 24 25 |
# File 'app/presenters/hyrax/pcdm_member_presenter_factory.rb', line 22 def initialize(object, ability, _request = nil) @object = object @ability = ability end |
Instance Attribute Details
#ability ⇒ Object (readonly)
Returns the value of attribute ability.
17 18 19 |
# File 'app/presenters/hyrax/pcdm_member_presenter_factory.rb', line 17 def ability @ability end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
17 18 19 |
# File 'app/presenters/hyrax/pcdm_member_presenter_factory.rb', line 17 def object @object end |
Instance Method Details
#file_set_presenters ⇒ Array<FileSetPresenter, WorkShowPresenter>, Enumerator<FileSetPresenter>
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/presenters/hyrax/pcdm_member_presenter_factory.rb', line 30 def file_set_presenters return enum_for(:file_set_presenters).to_a unless block_given? results = query_docs(generic_type: "FileSet") object.member_ids.each do |id| id = id.to_s indx = results.index { |doc| id == doc['id'] } next if indx.nil? hash = results.delete_at(indx) yield presenter_for(document: ::SolrDocument.new(hash), ability: ability) end end |
#member_presenters ⇒ Array<FileSetPresenter, WorkShowPresenter> #member_presenters ⇒ Array<FileSetPresenter, WorkShowPresenter>
Note:
defaults to using ‘object.member_ids`. passing a specific set of ids is supported for compatibility with MemberPresenterFactory, but we recommend making sparing use of this feature.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/presenters/hyrax/pcdm_member_presenter_factory.rb', line 56 def member_presenters(ids = object.member_ids) return enum_for(:member_presenters, ids).to_a unless block_given? results = query_docs(ids: ids) ids.each do |id| id = id.to_s indx = results.index { |doc| id == doc['id'] } raise(Hyrax::ObjectNotFoundError, "Could not find an indexed document for id: #{id}") if indx.nil? hash = results.delete_at(indx) yield presenter_for(document: ::SolrDocument.new(hash), ability: ability) end end |
#ordered_ids ⇒ Array<#to_s>
73 74 75 |
# File 'app/presenters/hyrax/pcdm_member_presenter_factory.rb', line 73 def ordered_ids object.member_ids end |
#presenter_for(document:, ability:) ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'app/presenters/hyrax/pcdm_member_presenter_factory.rb', line 98 def presenter_for(document:, ability:) case document['has_model_ssim'].first when *Hyrax::ModelRegistry.file_set_rdf_representations file_presenter_class.new(document, ability) else work_presenter_class.new(document, ability) end end |
#work_presenters ⇒ Array<WorkShowPresenter>
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/presenters/hyrax/pcdm_member_presenter_factory.rb', line 79 def work_presenters return enum_for(:work_presenters) unless block_given? results = query_docs(generic_type: "Work") object.member_ids.each do |id| id = id.to_s indx = results.index { |doc| id == doc['id'] } next if indx.nil? hash = results.delete_at(indx) yield presenter_for(document: ::SolrDocument.new(hash), ability: ability) end end |