class Dry::Types::Constructor
def self.new(input, options = {}, &block)
-
block
(#call, nil
) -- -
options
(Hash
) -- -
input
(Builder, Object
) --
def self.new(input, options = {}, &block) type = input.is_a?(Builder) ? input : Definition.new(input) super(type, options, &block) end
def call(input)
-
(Object)
-
Parameters:
-
input
(Object
) --
def call(input) type[fn[input]] end
def constrained_type
-
(Class)
-
def constrained_type Constrained::Coercible end
def constructor(new_fn = nil, **options, &block)
-
(Constructor)
-
Parameters:
-
block
(#call, nil
) -- -
options
(Hash
) -- -
new_fn
(#call, nil
) --
def constructor(new_fn = nil, **options, &block) left = new_fn || block right = fn with(options.merge(fn: -> input { left[right[input]] })) end
def initialize(type, options = {}, &block)
-
block
(#call, nil
) -- -
options
(Hash
) -- -
type
(Type
) --
def initialize(type, options = {}, &block) @type = type @fn = options.fetch(:fn, block) super end
def method_missing(meth, *args, &block)
-
block
(#call, nil
) -- -
args
(Array
) -- -
meth
(Symbol
) --
def method_missing(meth, *args, &block) if type.respond_to?(meth) response = type.__send__(meth, *args, &block) if response.kind_of?(Builder) self.class.new(response, options) else response end else super end end
def primitive
-
(Class)
-
def primitive type.primitive end
def respond_to_missing?(meth, include_private = false)
-
(Boolean)
-
Parameters:
-
include_private
(Boolean
) -- -
meth
(Symbol
) --
def respond_to_missing?(meth, include_private = false) super || type.respond_to?(meth) end
def try(input, &block)
-
(Object)
- if block given and try fails -
(Logic::Result, Types::Result)
-
Parameters:
-
block
(#call, nil
) -- -
input
(Object
) --
def try(input, &block) type.try(fn[input], &block) rescue TypeError => e failure(input, e.message) end
def valid?(value)
-
(Boolean)
-
Parameters:
-
value
(Object
) --
def valid?(value) super && type.valid?(value) end