Class: Interdependence::Types::FieldCoercer

Inherits:
Object
  • Object
show all
Defined in:
lib/interdependence/types.rb

Overview

Coerce arguments into fields

Class Method Summary collapse

Class Method Details

.call(value) ⇒ Field, UnsetField

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Coerce different field values

  • Coercions:

    • Symbol -> Field

    • Field -> clone

    • nil -> UnsetField

Parameters:

  • value (input value)

Returns:



114
115
116
117
118
119
120
# File 'lib/interdependence/types.rb', line 114

def self.call(value)
  case value
  when Symbol       then Field.new(value)
  when Field        then value.clone
  when nil          then UnsetField.new
  end
end

.success?(primitive, value) ⇒ TrueClass, FalseClass

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Was the field successfully coerced into a field or UnsetField?

Parameters:

  • primitive (Class)
    Field primitive
  • value (coerced value)

Returns:

  • (TrueClass, FalseClass)
    outcome


131
132
133
# File 'lib/interdependence/types.rb', line 131

def self.success?(primitive, value)
  value.instance_of?(primitive) || value.instance_of?(UnsetField)
end