Class: Typero::BooleanType
- Defined in:
- lib/typero/type/types/boolean_type.rb
Constant Summary
Constants inherited from Type
Type::ERRORS, Type::OPTS, Type::OPTS_KEYS
Instance Attribute Summary
Attributes inherited from Type
Instance Method Summary collapse
Methods inherited from Type
allowed_opt?, #db_field, db_schema, #default, error, #get, #initialize, load, opts, #value
Constructor Details
This class inherits a constructor from Typero::Type
Instance Method Details
#db_schema ⇒ Object
20 21 22 23 24 |
# File 'lib/typero/type/types/boolean_type.rb', line 20 def db_schema [:boolean, { default: opts[:default] || false }] end |
#set ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/typero/type/types/boolean_type.rb', line 4 def set value do |_| bool = _.to_s if value == '' false elsif %w(true 1 on).include?(bool) true elsif %w(false 0 off).include?(bool) false else error_for :unsupported_boolean, bool end end end |