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
8
9
10
11
# File 'lib/taro/types/shared/object_coercion.rb', line 3

def coerce_input
  validate_no_undeclared_params
  result = {}
  self.class.fields.each do |name, field|
    value = field.value_for_input(object)
    result[name] = value unless value.equal?(Taro::None)
  end
  result
end

#coerce_responseObject

Render the object into a hash.



14
15
16
17
18
19
# File 'lib/taro/types/shared/object_coercion.rb', line 14

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