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


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

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


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

def id
  @id
end

#work_relationObject (readonly)

Returns the value of attribute work_relation


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

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


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

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

#to_sObject


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

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

#workObject


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

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