Class: Hyrax::PcdmMemberPresenterFactory

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(object, ability) ⇒ PcdmMemberPresenterFactory

Returns a new instance of PcdmMemberPresenterFactory.

Parameters:

  • object (#member_ids)
  • ability (::Ability)

22
23
24
25
# File 'app/presenters/hyrax/pcdm_member_presenter_factory.rb', line 22

def initialize(object, ability)
  @object = object
  @ability = ability
end

Instance Attribute Details

#abilityObject (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

#objectObject (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_presentersArray<FileSetPresenter, WorkShowPresenter>, Enumerator<FileSetPresenter>

Returns:


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) 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_presentersEnumerator<FileSetPresenter, WorkShowPresenter> #member_presentersEnumerator<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.

Overloads:


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) unless block_given?

  results = query_docs(ids: ids)

  ids.each do |id|
    id = id.to_s
    indx = results.index { |doc| id == doc['id'] }
    raise(ArgumentError, "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_idsArray<#to_s>

Returns:

  • (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

Parameters:

  • document (::SolrDocument)
  • ability (::Ability)

Returns:


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::FileSet.name
    Hyrax::FileSetPresenter.new(document, ability)
  else
    Hyrax::WorkShowPresenter.new(document, ability)
  end
end

#work_presentersArray<WorkShowPresenter>

Returns:


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