Class: Hyrax::WorkQueryService

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/work_query_service.rb

Overview

Note:

This was extracted from the ProxyDepositRequest, which was coordinating lots of effort. It was also an ActiveRecord object that required lots of Fedora/Solr interactions.

Responsible for retrieving information based on the given work.

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, work_relation: default_work_relation) ⇒ WorkQueryService

Returns a new instance of WorkQueryService.

Parameters:

  • id (String)
    • The id of the work

  • work_relation (#exists?, #find) (defaults to: default_work_relation)
    • How we will query some of the related information



14
15
16
17
# File 'app/services/hyrax/work_query_service.rb', line 14

def initialize(id:, work_relation: default_work_relation)
  @id = id
  @work_relation = work_relation
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



18
19
20
# File 'app/services/hyrax/work_query_service.rb', line 18

def id
  @id
end

#work_relationObject (readonly)

Returns the value of attribute work_relation.



18
19
20
# File 'app/services/hyrax/work_query_service.rb', line 18

def work_relation
  @work_relation
end

Instance Method Details

#deleted_work?Boolean

Returns if the work has been deleted.

Returns:

  • (Boolean)

    if the work has been deleted



29
30
31
# File 'app/services/hyrax/work_query_service.rb', line 29

def deleted_work?
  !work_relation.exists?(id)
end

#to_sObject



37
38
39
40
41
42
43
# File 'app/services/hyrax/work_query_service.rb', line 37

def to_s
  if deleted_work?
    'work not found'
  else
    solr_doc.to_s
  end
end

#workObject



33
34
35
# File 'app/services/hyrax/work_query_service.rb', line 33

def work
  @work ||= work_relation.find(id)
end