Module: RSchema::Coercers::Boolean
Overview
Coerces certain strings, and nil, to true or false
Constant Summary collapse
- TRUTHY_STRINGS =
%w[on 1 true yes].freeze
- FALSEY_STRINGS =
%w[off 0 false no].freeze
Instance Method Summary collapse
Instance Method Details
#build(_schema) ⇒ Object
14 15 16 |
# File 'lib/rschema/coercers/boolean.rb', line 14 def build(_schema) self end |
#call(value) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/rschema/coercers/boolean.rb', line 18 def call(value) case value when true, false then Result.success(value) when nil then Result.success(false) when String then coerce_string(value) else Result.failure end end |
#will_affect?(value) ⇒ Boolean
27 28 29 |
# File 'lib/rschema/coercers/boolean.rb', line 27 def will_affect?(value) value != true && value != false end |