diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2016-12-31 21:54:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-31 21:54:20 +0100 |
commit | e632c2fa4cb60072a778ce95c952a0fa95e5b074 (patch) | |
tree | ee120468aa0e7469c9436487a6ae33a0f34dd283 /activemodel | |
parent | 334a7dcf107cd3ff1697163d331d289d6d65dcd7 (diff) | |
parent | d8e5751a1d7ad027519463134fe1a861d02494fc (diff) | |
download | rails-e632c2fa4cb60072a778ce95c952a0fa95e5b074.tar.gz rails-e632c2fa4cb60072a778ce95c952a0fa95e5b074.tar.bz2 rails-e632c2fa4cb60072a778ce95c952a0fa95e5b074.zip |
Merge pull request #27528 from kamipo/extract_casted_booleans
Extract `casted_true`/`casted_false` for `Type::ImmutableString`
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/type/immutable_string.rb | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/activemodel/lib/active_model/type/immutable_string.rb b/activemodel/lib/active_model/type/immutable_string.rb index 58268540e5..c967d428ac 100644 --- a/activemodel/lib/active_model/type/immutable_string.rb +++ b/activemodel/lib/active_model/type/immutable_string.rb @@ -8,8 +8,8 @@ module ActiveModel def serialize(value) case value when ::Numeric, ActiveSupport::Duration then value.to_s - when true then "t" - when false then "f" + when true then casted_true + when false then casted_false else super end end @@ -19,12 +19,20 @@ module ActiveModel def cast_value(value) result = \ case value - when true then "t" - when false then "f" + when true then casted_true + when false then casted_false else value.to_s end result.freeze end + + def casted_true + "t".freeze + end + + def casted_false + "f".freeze + end end end end |