Class: Valkyrie::Persistence::Solr::ModelConverter
- Inherits:
-
Object
- Object
- Valkyrie::Persistence::Solr::ModelConverter
- Defined in:
- lib/valkyrie/persistence/solr/model_converter.rb
Overview
Responsible for converting a Resource into hashes for indexing into Solr.
Defined Under Namespace
Classes: BooleanPropertyValue, CompositeSolrRow, DateTimePropertyValue, EnumerableValue, IDPropertyValue, IntegerPropertyValue, LiteralPropertyValue, NestedObjectValue, NilPropertyValue, Property, SharedStringPropertyValue, SolrMapperValue, SolrRow, StringPropertyValue, URIPropertyValue
Instance Attribute Summary collapse
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#resource_factory ⇒ Object
readonly
Returns the value of attribute resource_factory.
Instance Method Summary collapse
- #convert! ⇒ Object
-
#created_at ⇒ String
ISO-8601 timestamp in UTC of the created_at for this solr document.
-
#id ⇒ String
The solr document ID.
- #indexer_solr(resource) ⇒ Object
-
#initialize(resource, resource_factory:) ⇒ ModelConverter
constructor
A new instance of ModelConverter.
-
#to_h ⇒ Hash
Solr document to index.
Constructor Details
#initialize(resource, resource_factory:) ⇒ ModelConverter
Returns a new instance of ModelConverter.
8 9 10 11 |
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 8 def initialize(resource, resource_factory:) @resource = resource @resource_factory = resource_factory end |
Instance Attribute Details
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
6 7 8 |
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 6 def resource @resource end |
#resource_factory ⇒ Object (readonly)
Returns the value of attribute resource_factory.
6 7 8 |
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 6 def resource_factory @resource_factory end |
Instance Method Details
#convert! ⇒ Object
13 14 15 16 |
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 13 def convert! to_h.merge(Valkyrie::Persistence::Solr::Queries::MODEL.to_sym => [resource.internal_resource]) .merge(indexer_solr(resource)) end |
#created_at ⇒ String
Returns ISO-8601 timestamp in UTC of the created_at for this solr document.
29 30 31 32 33 34 35 |
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 29 def created_at if resource_attributes[:created_at] DateTime.parse(resource_attributes[:created_at].to_s).utc.iso8601 else Time.current.utc.iso8601 end end |
#id ⇒ String
Returns The solr document ID.
23 24 25 |
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 23 def id resource.id.to_s end |
#indexer_solr(resource) ⇒ Object
18 19 20 |
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 18 def indexer_solr(resource) resource_indexer.new(resource: resource).to_solr end |
#to_h ⇒ Hash
Returns Solr document to index.
38 39 40 41 42 43 44 |
# File 'lib/valkyrie/persistence/solr/model_converter.rb', line 38 def to_h { "id": id, "join_id_ssi": "id-#{id}", "created_at_dtsi": created_at }.merge(attribute_hash) end |