Class: Valkyrie::Persistence::Solr::Queries::FindByIdQuery
- Inherits:
-
Object
- Object
- Valkyrie::Persistence::Solr::Queries::FindByIdQuery
- Defined in:
- lib/valkyrie/persistence/solr/queries/find_by_id_query.rb
Overview
Responsible for returning a single resource identified by an ID.
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#id ⇒ String
Retrieve the string value for the ID.
-
#resource_factory ⇒ Object
readonly
Returns the value of attribute resource_factory.
Instance Method Summary collapse
-
#initialize(id, connection:, resource_factory:) ⇒ FindByIdQuery
constructor
A new instance of FindByIdQuery.
-
#resource ⇒ Hash
Query Solr for for the first document with the ID in a field.
-
#run ⇒ Valkyrie::Resource
Constructs a Valkyrie Resource found using the ID.
Constructor Details
#initialize(id, connection:, resource_factory:) ⇒ FindByIdQuery
Returns a new instance of FindByIdQuery.
11 12 13 14 15 |
# File 'lib/valkyrie/persistence/solr/queries/find_by_id_query.rb', line 11 def initialize(id, connection:, resource_factory:) @id = id @connection = connection @resource_factory = resource_factory end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
5 6 7 |
# File 'lib/valkyrie/persistence/solr/queries/find_by_id_query.rb', line 5 def connection @connection end |
#id ⇒ String
Retrieve the string value for the ID
27 28 29 |
# File 'lib/valkyrie/persistence/solr/queries/find_by_id_query.rb', line 27 def id @id.to_s end |
#resource_factory ⇒ Object (readonly)
Returns the value of attribute resource_factory.
5 6 7 |
# File 'lib/valkyrie/persistence/solr/queries/find_by_id_query.rb', line 5 def resource_factory @resource_factory end |
Instance Method Details
#resource ⇒ Hash
Query Solr for for the first document with the ID in a field
33 34 35 |
# File 'lib/valkyrie/persistence/solr/queries/find_by_id_query.rb', line 33 def resource @resource ||= connection.get("select", params: { q: "id:\"#{id}\"", fl: "*", rows: 1 })["response"]["docs"].first end |
#run ⇒ Valkyrie::Resource
Constructs a Valkyrie Resource found using the ID
20 21 22 23 |
# File 'lib/valkyrie/persistence/solr/queries/find_by_id_query.rb', line 20 def run raise ::Valkyrie::Persistence::ObjectNotFoundError unless resource resource_factory.to_resource(object: resource) end |