diff options
author | Yves Senn <yves.senn@gmail.com> | 2015-01-15 22:56:43 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2015-01-15 22:56:43 +0100 |
commit | 2c5a0ddeda523f0e4beab3aa3f39407c6b1c427c (patch) | |
tree | 57d6c9d7141294c13b58a82de7d5726e640b3729 /activerecord/lib | |
parent | 9a027d10a68f6cd7420a19fef3aa63e348a132eb (diff) | |
parent | 1be562db9501007bd82d9385ffc8ca59e23daba9 (diff) | |
download | rails-2c5a0ddeda523f0e4beab3aa3f39407c6b1c427c.tar.gz rails-2c5a0ddeda523f0e4beab3aa3f39407c6b1c427c.tar.bz2 rails-2c5a0ddeda523f0e4beab3aa3f39407c6b1c427c.zip |
Merge pull request #18543 from henrik/integer_limit_or_default
Tiny: DRY default limit in ActiveRecord::Type::Integer
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/type/integer.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/type/integer.rb b/activerecord/lib/active_record/type/integer.rb index fc260a081a..394fe008f9 100644 --- a/activerecord/lib/active_record/type/integer.rb +++ b/activerecord/lib/active_record/type/integer.rb @@ -3,6 +3,10 @@ module ActiveRecord class Integer < Value # :nodoc: include Numeric + # Column storage size in bytes. + # 4 bytes means a MySQL int or Postgres integer as opposed to smallint etc. + DEFAULT_LIMIT = 4 + def initialize(*) super @range = min_value...max_value @@ -38,12 +42,12 @@ module ActiveRecord def ensure_in_range(value) unless range.cover?(value) - raise RangeError, "#{value} is out of range for #{self.class} with limit #{limit || 4}" + raise RangeError, "#{value} is out of range for #{self.class} with limit #{limit || DEFAULT_LIMIT}" end end def max_value - limit = self.limit || 4 + limit = self.limit || DEFAULT_LIMIT 1 << (limit * 8 - 1) # 8 bits per byte with one bit for sign end |