Class: Hyrax::WorkResourceQueryService
- Inherits:
-
Object
- Object
- Hyrax::WorkResourceQueryService
- Defined in:
- app/services/hyrax/work_resource_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.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
-
#deleted_work? ⇒ Boolean
If the work has been deleted.
-
#initialize(id:) ⇒ WorkResourceQueryService
constructor
A new instance of WorkResourceQueryService.
- #to_s ⇒ Object
- #work ⇒ Object
Constructor Details
#initialize(id:) ⇒ WorkResourceQueryService
Returns a new instance of WorkResourceQueryService.
11 12 13 |
# File 'app/services/hyrax/work_resource_query_service.rb', line 11 def initialize(id:) @id = id end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
14 15 16 |
# File 'app/services/hyrax/work_resource_query_service.rb', line 14 def id @id end |
Instance Method Details
#deleted_work? ⇒ Boolean
Returns if the work has been deleted.
17 18 19 20 21 22 |
# File 'app/services/hyrax/work_resource_query_service.rb', line 17 def deleted_work? Hyrax.query_service.find_by(id: id) false rescue Valkyrie::Persistence::ObjectNotFoundError true end |
#to_s ⇒ Object
31 32 33 34 35 36 37 |
# File 'app/services/hyrax/work_resource_query_service.rb', line 31 def to_s if deleted_work? 'work not found' else solr_doc.to_s end end |
#work ⇒ Object
24 25 26 27 28 29 |
# File 'app/services/hyrax/work_resource_query_service.rb', line 24 def work # Need to ensure it is a work? resource = Hyrax.query_service.find_by(id: id) raise ModelMismatchError, "Expected work but got #{resource.class}" unless resource.work? resource end |