class RailsParam::Coercion

Constants

BOOLEAN_TYPES
PARAM_TYPE_MAPPING
TIME_TYPES

Attributes

coercion[R]
param[R]

Public Class Methods

new(param, type, options) click to toggle source
# File lib/rails_param/coercion.rb, line 23
def initialize(param, type, options)
  @param = param
  @coercion = klass_for(type).new(param: param, options: options, type: type)
end

Public Instance Methods

coerce() click to toggle source
# File lib/rails_param/coercion.rb, line 35
def coerce
  return nil if param.nil?

  coercion.coerce
end
klass_for(type) click to toggle source
# File lib/rails_param/coercion.rb, line 28
def klass_for(type)
  klass = PARAM_TYPE_MAPPING[type]
  return klass if klass

  raise TypeError
end