aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/type/integer.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-02-17 21:00:39 +0900
committerRyuta Kamizono <kamipo@gmail.com>2019-02-18 13:16:33 +0900
commit1dfd01475d93b8801df0a2933094b437a607e3e2 (patch)
treeda5f7773f1e4077a65180cfbc0bc475a6d55f882 /activemodel/lib/active_model/type/integer.rb
parent9379d553d8669a99b55368715ccc48645f0441d2 (diff)
downloadrails-1dfd01475d93b8801df0a2933094b437a607e3e2.tar.gz
rails-1dfd01475d93b8801df0a2933094b437a607e3e2.tar.bz2
rails-1dfd01475d93b8801df0a2933094b437a607e3e2.zip
Extract duplicated `serialize` methods into helpers
Since `serialize` is passed user input args (from `where`, schema default, etc), a helper should provide `serialize` if the helper also provide `cast`. Related #32624, 34cc301, a741208.
Diffstat (limited to 'activemodel/lib/active_model/type/integer.rb')
-rw-r--r--activemodel/lib/active_model/type/integer.rb9
1 files changed, 2 insertions, 7 deletions
diff --git a/activemodel/lib/active_model/type/integer.rb b/activemodel/lib/active_model/type/integer.rb
index da74aaa3c5..5878b94171 100644
--- a/activemodel/lib/active_model/type/integer.rb
+++ b/activemodel/lib/active_model/type/integer.rb
@@ -24,7 +24,7 @@ module ActiveModel
end
def serialize(value)
- result = cast(value)
+ result = super
if result
ensure_in_range(result)
end
@@ -35,12 +35,7 @@ module ActiveModel
attr_reader :range
def cast_value(value)
- case value
- when true then 1
- when false then 0
- else
- value.to_i rescue nil
- end
+ value.to_i rescue nil
end
def ensure_in_range(value)