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



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

def self.instance
  @instance ||= new
end

Instance Method Details

#call(value, options) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rschema/schemas/boolean.rb', line 18

def call(value, options)
  if value.equal?(true) || value.equal?(false)
    Result.success(value)
  else
    Result.failure(Error.new(
      schema: self,
      value: value,
      symbolic_name: :not_a_boolean,
    ))
  end
end

#with_wrapped_subschemas(wrapper) ⇒ Object



30
31
32
# File 'lib/rschema/schemas/boolean.rb', line 30

def with_wrapped_subschemas(wrapper)
  self
end