Class: Valkyrie::Persistence::Shared::JSONValueMapper

Inherits:
Object
  • Object
show all
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

Postgres::ORMConverter::RDFMetadata

Defined Under Namespace

Classes: DateValue, EnumeratorValue, HashValue, IDValue, NestedRecord, PostgresValue, URIValue

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(metadata) ⇒ JSONValueMapper

Returns a new instance of JSONValueMapper.

Parameters:

  • metadata (Hash)


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

#metadataObject (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

#resultHash

Convert the database attribute values and map these to the existing keys in the Valkyrie Resource metadata

Returns:

  • (Hash)


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