Module: Taro::Types::Shared::ObjectCoercion

Included in:
ObjectType
Defined in:
lib/taro/types/shared/object_coercion.rb

Overview

Provides input and response handling for types with fields.

Instance Method Summary collapse

Instance Method Details

#coerce_inputObject



3
4
5
6
7
# File 'lib/taro/types/shared/object_coercion.rb', line 3

def coerce_input
  self.class.fields.transform_values do |field|
    field.value_for_input(object)
  end
end

#coerce_responseObject

Render the object into a hash.



10
11
12
13
14
15
# File 'lib/taro/types/shared/object_coercion.rb', line 10

def coerce_response
  object_is_hash = object.is_a?(Hash)
  self.class.fields.transform_values do |field|
    field.value_for_response(object, context: self, object_is_hash:)
  end
end