1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
# frozen_string_literal: true
require 'dry/types/coercions/params'
module Dry
module Types
register('params.nil') do
self['nominal.nil'].constructor(Coercions::Params.method(:to_nil))
end
register('params.date') do
self['nominal.date'].constructor(Coercions::Params.method(:to_date))
end
register('params.date_time') do
self['nominal.date_time'].constructor(Coercions::Params.method(:to_date_time))
end
register('params.time') do
self['nominal.time'].constructor(Coercions::Params.method(:to_time))
end
register('params.true') do
self['nominal.true'].constructor(Coercions::Params.method(:to_true))
end
register('params.false') do
self['nominal.false'].constructor(Coercions::Params.method(:to_false))
end
register('params.bool') do
self['params.true'] | self['params.false']
end
register('params.integer') do
self['nominal.integer'].constructor(Coercions::Params.method(:to_int))
end
register('params.float') do
self['nominal.float'].constructor(Coercions::Params.method(:to_float))
end
register('params.decimal') do
self['nominal.decimal'].constructor(Coercions::Params.method(:to_decimal))
end
register('params.array') do
self['nominal.array'].constructor(Coercions::Params.method(:to_ary))
end
register('params.hash') do
self['nominal.hash'].constructor(Coercions::Params.method(:to_hash))
end
register('params.symbol') do
self['nominal.symbol'].constructor(Coercions::Params.method(:to_symbol))
end
COERCIBLE.each_key do |name|
next if name.equal?(:string)
register("optional.params.#{name}", self['params.nil'] | self["params.#{name}"])
end
end
end
|