aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/type
diff options
context:
space:
mode:
authorDavid Elliott <david@philosophie.is>2016-06-29 09:27:22 -0700
committerDavid Elliott <david@philosophie.is>2016-07-11 07:29:58 -0700
commit3691c751e9cd0bd8dcbcbaf9824d64b740ade7ad (patch)
tree0fcddc22fc05e54260ad3c5eb2fb4155740dfe55 /activemodel/lib/active_model/type
parent79bc06647ccb77840877f2d8e3dcf620460d7306 (diff)
downloadrails-3691c751e9cd0bd8dcbcbaf9824d64b740ade7ad.tar.gz
rails-3691c751e9cd0bd8dcbcbaf9824d64b740ade7ad.tar.bz2
rails-3691c751e9cd0bd8dcbcbaf9824d64b740ade7ad.zip
[ci skip] add class level documentation to ActiveModel::Type::Boolean
add documentation of the behaviors of type coercion at the class level
Diffstat (limited to 'activemodel/lib/active_model/type')
-rw-r--r--activemodel/lib/active_model/type/boolean.rb15
1 files changed, 13 insertions, 2 deletions
diff --git a/activemodel/lib/active_model/type/boolean.rb b/activemodel/lib/active_model/type/boolean.rb
index c1bce98c87..4e9d06a3ce 100644
--- a/activemodel/lib/active_model/type/boolean.rb
+++ b/activemodel/lib/active_model/type/boolean.rb
@@ -1,9 +1,20 @@
module ActiveModel
module Type
- class Boolean < Value # :nodoc:
+ # == 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+
+ class Boolean < Value
FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF'].to_set
- def type
+ def type # :nodoc:
:boolean
end