Class: Attributor::Boolean
- Inherits:
-
Object
- Object
- Attributor::Boolean
- Includes:
- Type
- Defined in:
- lib/attributor/types/boolean.rb
Class Method Summary collapse
- .example(context = nil, options: {}) ⇒ Object
- .family ⇒ Object
- .load(value, context = Attributor::DEFAULT_ROOT_CONTEXT, **options) ⇒ Object
- .valid_type?(value) ⇒ Boolean
Methods included from Type
Class Method Details
.example(context = nil, options: {}) ⇒ Object
14 15 16 |
# File 'lib/attributor/types/boolean.rb', line 14 def self.example(context=nil, options: {}) [true, false].sample end |
.family ⇒ Object
27 28 29 |
# File 'lib/attributor/types/boolean.rb', line 27 def self.family 'boolean' end |
.load(value, context = Attributor::DEFAULT_ROOT_CONTEXT, **options) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/attributor/types/boolean.rb', line 18 def self.load(value,context=Attributor::DEFAULT_ROOT_CONTEXT, **) return nil if value.nil? raise CoercionError, 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, context: context, from: value.class, to: self end |
.valid_type?(value) ⇒ Boolean
10 11 12 |
# File 'lib/attributor/types/boolean.rb', line 10 def self.valid_type?(value) value == true || value == false end |