class Virtus::Coercer

Abstract coercer class

Attributes

primitive[R]

@api private

type[R]

@api private

Public Class Methods

new(type) click to toggle source

@api private

# File lib/virtus/coercer.rb, line 11
def initialize(type)
  @type      = type
  @primitive = type.primitive
end

Public Instance Methods

call(input) click to toggle source

Coerce input value into expected primitive type

@param [Object] input

@return [Object] coerced input

@api public

# File lib/virtus/coercer.rb, line 23
def call(input)
  NotImplementedError.new("#{self.class}#call must be implemented")
end
success?(primitive, input) click to toggle source

Return if the input value was successfuly coerced

@param [Object] input

@return [Object] coerced input

@api public

# File lib/virtus/coercer.rb, line 34
def success?(primitive, input)
  input.kind_of?(primitive)
end