class Virtus::Attribute::Coercer

Coercer accessor wrapper

@api private

Attributes

coercers[R]

@api private

method[R]

@api private

Public Class Methods

new(type, coercers) click to toggle source

Initialize a new coercer object

@param [Object] coercers accessor @param [Symbol] coercion method

@return [undefined]

@api private

Calls superclass method Virtus::Coercer.new
# File lib/virtus/attribute/coercer.rb, line 20
def initialize(type, coercers)
  super(type)
  @method   = type.coercion_method
  @coercers = coercers
end

Public Instance Methods

call(value) click to toggle source

Coerce given value

@return [Object]

@api private

# File lib/virtus/attribute/coercer.rb, line 31
def call(value)
  coercers[value.class].public_send(method, value)
rescue ::Coercible::UnsupportedCoercion
  value
end
success?(primitive, value) click to toggle source

@api public

# File lib/virtus/attribute/coercer.rb, line 38
def success?(primitive, value)
  coercers[primitive].coerced?(value)
end