Class: ActiveModel::Type::Boolean

Inherits:
Value
  • Object
show all
Defined in:
lib/active_model/type/boolean.rb

Overview

Active Model Type Boolean

A class that behaves like a boolean type, including rules for coercion of user input.

Coercion

Values set from user input will first be coerced into the appropriate ruby type. Coercion behavior is roughly mapped to Ruby’s boolean semantics.

  • “false”, “f” , “0”, 0 or any other value in FALSE_VALUES will be coerced to false

  • Empty strings are coerced to nil

  • All other values will be coerced to true

Constant Summary collapse

FALSE_VALUES =
[false, 0, "0", "f", "F", "false", "FALSE", "off", "OFF"].to_set

Instance Attribute Summary

Attributes inherited from Value

#limit, #precision, #scale

Instance Method Summary collapse

Methods inherited from Value

#==, #assert_valid_value, #binary?, #cast, #changed?, #changed_in_place?, #deserialize, #hash, #initialize, #map, #serialize, #type_cast_for_schema

Constructor Details

This class inherits a constructor from ActiveModel::Type::Value

Instance Method Details

#typeObject

:nodoc:



17
18
19
# File 'lib/active_model/type/boolean.rb', line 17

def type # :nodoc:
  :boolean
end