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

Inherits:
ValueMapper
  • Object
show all
Defined in:
lib/valkyrie/persistence/shared/json_value_mapper.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)


113
114
115
# File 'lib/valkyrie/persistence/shared/json_value_mapper.rb', line 113

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>)


121
122
123
124
125
126
127
128
129
# File 'lib/valkyrie/persistence/shared/json_value_mapper.rb', line 121

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