Class: Rabarber::Inputs::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/rabarber/inputs/base.rb

Direct Known Subclasses

Boolean, Context, DynamicRule, Model, NonEmptyString, Role, Roles, Symbol

Instance Method Summary collapse

Constructor Details

#initialize(value, optional: false, error: Rabarber::InvalidArgumentError, message: nil) ⇒ Base



10
11
12
13
14
15
# File 'lib/rabarber/inputs/base.rb', line 10

def initialize(value, optional: false, error: Rabarber::InvalidArgumentError, message: nil)
  @value = value
  @optional = optional
  @error = error
  @message = message
end

Instance Method Details

#processObject



17
18
19
20
21
22
# File 'lib/rabarber/inputs/base.rb', line 17

def process
  type_checker = @optional ? type.optional : type
  type_checker[@value]
rescue Dry::Types::CoercionError
  raise_error
end