class Dry::Types::Constructor

def self.new(input, options = {}, &block)

Parameters:
  • 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)

Returns:
  • (Object) -

Parameters:
  • input (Object) --
def call(input)
  type[fn[input]]
end

def constrained_type

Returns:
  • (Class) -
def constrained_type
  Constrained::Coercible
end

def constructor(new_fn = nil, **options, &block)

Returns:
  • (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)

Parameters:
  • 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)

Parameters:
  • 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

Returns:
  • (Class) -
def primitive
  type.primitive
end

def respond_to_missing?(meth, include_private = false)

Returns:
  • (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)

Returns:
  • (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)

Returns:
  • (Boolean) -

Parameters:
  • value (Object) --
def valid?(value)
  super && type.valid?(value)
end