Class: Valkyrie::Persistence::Postgres::ORMConverter::RDFMetadata::EnumeratorValue

Inherits:
ValueMapper
  • Object
show all
Defined in:
lib/valkyrie/persistence/postgres/orm_converter.rb

Overview

Handles iterating over arrays of values and converting each value.

Instance Attribute Summary

Attributes inherited from ValueMapper

#calling_mapper, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ValueMapper

for, #initialize, register

Constructor Details

This class inherits a constructor from Valkyrie::ValueMapper

Class Method Details

.handles?(value) ⇒ Boolean

Determines whether or not a value has enumerable behavior

Parameters:

  • value (Object)

Returns:

  • (Boolean)


190
191
192
# File 'lib/valkyrie/persistence/postgres/orm_converter.rb', line 190

def self.handles?(value)
  value.respond_to?(:each)
end

Instance Method Details

#resultArray<Object>

Convert the elements in the enumerable value in Valkyrie attribute values Casts single-valued arrays to the first value, letting Types::Set and Types::Array handle converting it back.

Returns:

  • (Array<Object>)


198
199
200
201
202
203
204
205
206
# File 'lib/valkyrie/persistence/postgres/orm_converter.rb', line 198

def result
  if value.length == 1
    calling_mapper.for(value.first).result
  else
    value.map do |value|
      calling_mapper.for(value).result
    end
  end
end