class Dry::Types::Definition
def self.[](primitive)
-
(Type)
-
Parameters:
-
primitive
(Class
) --
def self.[](primitive) if primitive == ::Array Types::Array elsif primitive == ::Hash Types::Hash else self end end
def call(input)
-
(BasicObject)
-
Parameters:
-
input
(BasicObject
) --
def call(input) input end
def constrained?
-
(false)
-
def constrained? false end
def default?
-
(false)
-
def default? false end
def failure(input, error)
-
(Result::Failure)
-
Parameters:
-
(
) --
def failure(input, error) Result::Failure.new(input, error) end
def initialize(primitive, options = {})
-
options
(Hash
) -- -
primitive
(Type, Class
) --
def initialize(primitive, options = {}) super @primitive = primitive freeze end
def name
-
(String)
-
def name primitive.name end
def optional?
-
(false)
-
def optional? false end
def primitive?(value)
-
(Boolean)
-
Parameters:
-
value
(Object
) --
def primitive?(value) value.is_a?(primitive) end
def result(klass, *args)
-
(Object)
- new instance of the given +klass+
Parameters:
-
args
(Array
) -- arguments for the +klass#initialize+ method -
klass
(Object
) -- class of the result instance
def result(klass, *args) klass.new(*args) end
def success(input)
-
(Result::Success)
-
Parameters:
-
(
) --
def success(input) Result::Success.new(input) end
def to_ast(meta: true)
-
(Array)
-
Other tags:
- Api: - public
def to_ast(meta: true) [:definition, [primitive, meta ? self.meta : EMPTY_HASH]] end
def try(input, &block)
-
(nil)
- otherwise -
(Result, Logic::Result)
- when a block is not provided
Other tags:
- Yieldreturn: -
Other tags:
- Yieldparam: failure -
Parameters:
-
block
(#call, nil
) -- -
input
(Object
) --
def try(input, &block) if valid?(input) success(input) else failure = failure(input, "#{input.inspect} must be an instance of #{primitive}") block ? yield(failure) : failure end end