Class: Valkyrie::Persistence::Shared::JSONValueMapper
- Inherits:
-
Object
- Object
- Valkyrie::Persistence::Shared::JSONValueMapper
- Defined in:
- lib/valkyrie/persistence/shared/json_value_mapper.rb
Overview
Converts a hash representation of a Resource back into a Resource. Often useful for converting back from JSON.
Direct Known Subclasses
Defined Under Namespace
Classes: DateValue, EnumeratorValue, HashValue, IDValue, NestedRecord, PostgresValue, URIValue
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Instance Method Summary collapse
-
#initialize(metadata) ⇒ JSONValueMapper
constructor
A new instance of JSONValueMapper.
-
#result ⇒ Hash
Convert the database attribute values and map these to the existing keys in the Valkyrie Resource metadata.
Constructor Details
#initialize(metadata) ⇒ JSONValueMapper
Returns a new instance of JSONValueMapper.
9 10 11 12 13 |
# File 'lib/valkyrie/persistence/shared/json_value_mapper.rb', line 9 def initialize() # nil hash values are handled by the default state in dry-types # anyways, so don't bother processing them here. @metadata = .compact end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
6 7 8 |
# File 'lib/valkyrie/persistence/shared/json_value_mapper.rb', line 6 def @metadata end |
Instance Method Details
#result ⇒ Hash
Convert the database attribute values and map these to the existing keys in the Valkyrie Resource metadata
17 18 19 20 21 22 23 |
# File 'lib/valkyrie/persistence/shared/json_value_mapper.rb', line 17 def result Hash[ .map do |key, value| [key, PostgresValue.for(value).result] end ] end |