class Attributor::Boolean
Public Class Methods
example(_context = nil, options: {})
click to toggle source
# File lib/attributor/types/boolean.rb, line 13 def self.example(_context = nil, options: {}) [true, false].sample end
family()
click to toggle source
# File lib/attributor/types/boolean.rb, line 26 def self.family 'boolean' end
json_schema_type()
click to toggle source
# File lib/attributor/types/boolean.rb, line 30 def self.json_schema_type :boolean end
load(value, context = Attributor::DEFAULT_ROOT_CONTEXT, **_options)
click to toggle source
# File lib/attributor/types/boolean.rb, line 17 def self.load(value, context = Attributor::DEFAULT_ROOT_CONTEXT, **_options) return nil if value.nil? raise CoercionError.new(context: context, from: value.class, to: self, value: value) if value.is_a?(::Float) return false if [false, 'false', 'FALSE', '0', 0, 'f', 'F'].include?(value) return true if [true, 'true', 'TRUE', '1', 1, 't', 'T'].include?(value) raise CoercionError.new(context: context, from: value.class, to: self) end
valid_type?(value)
click to toggle source
# File lib/attributor/types/boolean.rb, line 9 def self.valid_type?(value) value == true || value == false end