Class: Virtus::Attributes::Boolean

Inherits:
Object show all
Defined in:
lib/virtus/attributes/boolean.rb

Constant Summary collapse

TRUE_VALUES =
[ 1, '1', 't', 'T', 'true',  'TRUE'  ].freeze
FALSE_VALUES =
[ 0, '0', 'f', 'F', 'false', 'FALSE' ].freeze
BOOLEAN_MAP =
Hash[
TRUE_VALUES.product([ true ]) + FALSE_VALUES.product([ false ]) ].freeze

Constants inherited from Attribute

Attribute::DEFAULT_ACCESSOR, Attribute::OPTIONS

Instance Attribute Summary

Attributes inherited from Attribute

#instance_variable_name, #model, #name, #options, #reader_visibility, #writer_visibility

Instance Method Summary collapse

Methods inherited from Attribute

#_create_writer, accept_options, accepted_options, #complex?, descendants, #get, #get!, inherited, #initialize, options, #set, #set!, #typecast

Constructor Details

This class inherits a constructor from Virtus::Attributes::Attribute

Instance Method Details

#primitive?(value) ⇒ Boolean

Returns:



11
12
13
# File 'lib/virtus/attributes/boolean.rb', line 11

def primitive?(value)
  value == true || value == false
end

#typecast_to_primitive(value, model = nil) ⇒ Object



15
16
17
# File 'lib/virtus/attributes/boolean.rb', line 15

def typecast_to_primitive(value, model = nil)
  BOOLEAN_MAP.fetch(value, value)
end