Class: RSchema::Schemas::Boolean

Inherits:
Object
  • Object
show all
Defined in:
lib/rschema/schemas/boolean.rb

Overview

A schema that matches only true and false

Examples:

The boolean schema

schema = RSchema.define { boolean }
schema.valid?(true)  #=> true
schema.valid?(false) #=> true
schema.valid?(nil)   #=> false

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceObject


15
16
17
# File 'lib/rschema/schemas/boolean.rb', line 15

def self.instance
  @instance ||= new
end

Instance Method Details

#call(value, _options) ⇒ Object


19
20
21
22
23
24
25
# 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) ⇒ Object


27
28
29
# File 'lib/rschema/schemas/boolean.rb', line 27

def with_wrapped_subschemas(_wrapper)
  self
end