class RSchema::Schemas::Boolean
A schema that matches only `true` and `false`
@example The boolean schema
schema = RSchema.define { boolean } schema.valid?(true) #=> true schema.valid?(false) #=> true schema.valid?(nil) #=> false
Public Class Methods
instance()
click to toggle source
# File lib/rschema/schemas/boolean.rb, line 15 def self.instance @instance ||= new end
Public Instance Methods
call(value, _options)
click to toggle source
# File lib/rschema/schemas/boolean.rb, line 19 def call(value, _options) if value.equal?(true) || value.equal?(false) Result.success(value) else Result.failure(error(value)) end end
with_wrapped_subschemas(_wrapper)
click to toggle source
# File lib/rschema/schemas/boolean.rb, line 27 def with_wrapped_subschemas(_wrapper) self end
Private Instance Methods
error(value)
click to toggle source
# File lib/rschema/schemas/boolean.rb, line 33 def error(value) Error.new( schema: self, value: value, symbolic_name: :not_a_boolean, ) end