class Broi::Input

Constants

Invalid

Public Class Methods

attribute(name, **opts, &block) click to toggle source
Calls superclass method
# File lib/broi/input.rb, line 28
def attribute(name, **opts, &block)
  type = Types::Any.optional.meta(omittable: true)
  type = type.default(opts[:default]) if opts.has_key?(:default)
  super(name, type, &block)
end
call(params = {}) click to toggle source
# File lib/broi/input.rb, line 42
def call(params = {})
  result = validation.(params)
  input = Soft.(self, result.output, result.errors)
  if result.success?
    Success.new(input)
  else
    Failure.new(input, Errors.new(result.errors))
  end
end
validate(&block) click to toggle source
# File lib/broi/input.rb, line 34
def validate(&block)
  @validation = Dry::Validation::Schema(&block)
end
validation() click to toggle source
# File lib/broi/input.rb, line 38
def validation
  @validation ||= Dry::Validation.Schema {}
end

Private Class Methods

merge_error(input_value, error) click to toggle source
# File lib/broi/input.rb, line 54
def merge_error(input_value, error)
  if input_value.is_a? Hash

  else
    error ? InvalidValue.new : input_value
  end
end

Public Instance Methods

strict?() click to toggle source
# File lib/broi/input.rb, line 22
def strict?
  true
end