Class: Wings::EnumerableMapper

Inherits:
Valkyrie::ValueMapper
  • Object
show all
Defined in:
lib/wings/transformer_value_mapper.rb

Overview

Note:

a common value type this mapper handles is ‘ActiveTriples::Relation`

Maps enumerable values (e.g. Array, Enumerable, Hash, etc…) by calling the parent ‘ValueMapper` on each member.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.handles?(value) ⇒ Boolean

Parameters:

  • value (Object)

Returns:

  • (Boolean)


68
69
70
# File 'lib/wings/transformer_value_mapper.rb', line 68

def self.handles?(value)
  value.is_a?(Enumerable)
end

Instance Method Details

#resultEnumerable<Object>

Returns:

  • (Enumerable<Object>)


74
75
76
77
# File 'lib/wings/transformer_value_mapper.rb', line 74

def result
  return calling_mapper.for(value.first).result if value.length < 2
  value.map { |v| calling_mapper.for(v).result }
end