Sha256: 9d380c09b806b8eeee65e6c39a5f104269bba7aaf4798b34837875e2d096d012

Contents?: true

Size: 1.78 KB

Versions: 7

Compression:

Stored size: 1.78 KB

Contents

# 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

    register("params.string", self["string"])

    COERCIBLE.each_key do |name|
      next if name.equal?(:string)

      register("optional.params.#{name}", self["params.nil"] | self["params.#{name}"])
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dry-types-1.7.2 lib/dry/types/params.rb
dry-types-1.7.1 lib/dry/types/params.rb
dry-types-1.7.0 lib/dry/types/params.rb
dry-types-1.6.1 lib/dry/types/params.rb
dry-types-1.6.0 lib/dry/types/params.rb
dry-types-1.5.1 lib/dry/types/params.rb
dry-types-1.5.0 lib/dry/types/params.rb