Class: Valkyrie::Persistence::Shared::JSONValueMapper::EnumeratorValue
- Inherits:
-
ValueMapper
- Object
- ValueMapper
- Valkyrie::Persistence::Shared::JSONValueMapper::EnumeratorValue
- 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
Class Method Summary collapse
-
.handles?(value) ⇒ Boolean
Determines whether or not a value has enumerable behavior.
Instance Method Summary collapse
-
#result ⇒ Array<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.
Methods inherited from ValueMapper
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
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
#result ⇒ Array<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.
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 |