aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/type/integer.rb
Commit message (Collapse)AuthorAgeFilesLines
* Move ActiveRecord::Type to ActiveModelKir Shatrov2015-09-211-66/+0
| | | | The first step of bringing typecasting to ActiveModel
* Refactoring `ActiveRecord::Type::Integer` limityui-knk2015-05-181-3/+6
|
* Rm `Type#type_cast`Sean Griffin2015-02-171-1/+1
| | | | | | | | | This helper no longer makes sense as a separate method. Instead I'll just have `deserialize` call `cast` by default. This led to a random infinite loop in the `JSON` pg type, when it called `super` from `deserialize`. Not really a great way to fix that other than not calling super, or continuing to have the separate method, which makes the public API differ from what we say it is.
* `type_cast_for_database` -> `serialize`Sean Griffin2015-02-171-1/+1
|
* `Type#type_cast_from_database` -> `Type#deserialize`Sean Griffin2015-02-171-1/+1
|
* Move non-type objects into the `Type::Helpers` namespaceSean Griffin2015-02-071-1/+1
| | | | | | | The type code is actually quite accessible, and I'm planning to encourage people to look at the files in the `type` folder to learn more about how it works. This will help reduce the noise from code that is less about type casting, and more about random AR nonsense.
* Move integer range validation to never raise on assignmentSean Griffin2015-01-231-5/+9
| | | | | | | | | | | | | | | | | Given that this was originally added to normalize an error that would have otherwise come from the database (inconsistently), it's more natural for us to raise in `type_cast_for_database`, rather than `type_cast_from_user`. This way, things like numericality validators can handle it instead if the user chooses to do so. It also fixes an issue where assigning an out of range value would make it impossible to assign a new value later. This fixes several vague issues, none of which were ever directly reported, so I have no issue number to give. Places it was mentioned which I can remember: - https://github.com/thoughtbot/shoulda-matchers/blob/9ba21381d7caf045053a81f32df7de2f49687820/lib/shoulda/matchers/active_model/allow_value_matcher.rb#L261-L263 - https://github.com/rails/rails/issues/18653#issuecomment-71197026
* DRY default limit in ActiveRecord::Type::IntegerHenrik Nyh2015-01-151-2/+6
|
* Fix undesirable RangeError by Type::Integer. Add Type::UnsignedInteger.Ryuta Kamizono2014-12-121-1/+5
|
* Fix out of range error messageRyuta Kamizono2014-11-251-1/+1
|
* Speed up integer casting from DBSean Griffin2014-11-181-0/+5
| | | | | | | | We don't have the check the range when the value is coming from the DB, so override type_cast_from_database to short-circuit the extra work. The difference is huge but the absolute gain is quite small. That being said this is a hotspot and it showed up on the radar when benchmarking discourse.
* Revert "[PERF] Speed up integer type casting from DB"Godfrey Chan2014-11-171-4/+1
| | | | | | This reverts commit 6f7910a and 52c70d4. Query params are type cased through the same method, so this approach doesn't work.
* :nail_care: Put escape clause first, keeps @sgrif happy :grin:Godfrey Chan2014-11-171-1/+2
| | | | See comment on 6f7910a
* [PERF] Speed up integer type casting from DBGodfrey Chan2014-11-171-1/+3
| | | | | | | | | | | | | | | | | | | We don't have the check the range when the value is coming from the DB, so override type_cast_from_database to short-circuit the extra work. type_cast_from_database (small) 3437507.5 (±29.2%) i/s - 14223135 in 4.996973s type_cast_from_database (large) 3158588.7 (±28.3%) i/s - 13265628 in 4.992121s type_cast (small) 481984.8 (±14.2%) i/s - 2352012 in 5.005694s type_cast (large) 477331.8 (±14.2%) i/s - 2332824 in 5.012365s Comparison: type_cast_from_database (small): 3437507.5 i/s type_cast_from_database (large): 3158588.7 i/s - 1.09x slower type_cast (small): 481984.8 i/s - 7.13x slower type_cast (large): 477331.8 i/s - 7.20x slower The difference is huge but the absolute gain is quite small. That being said this is a hotspot and it showed up on the radar when benchmarking discourse.
* Use the correct values for int max and minSean Griffin2014-10-311-9/+13
| | | | | We had accidentally gone one power of two too far. In addition, we need to handle minimum values as well as the maximum.
* Treat strings greater than int max value as out of rangeSean Griffin2014-10-311-1/+20
| | | | | | | | | | | Sufficiently large integers cause `find` and `find_by` to raise `StatementInvalid` instead of `RecordNotFound` or just returning `nil`. Given that we can't cast to `nil` for `Integer` like we would with junk data for other types, we raise a `RangeError` instead, and rescue in places where it would be highly unexpected to get an exception from casting. Fixes #17380
* Removed unused `klass` definitions from typesSean Griffin2014-06-061-4/+0
| | | | Only `Date` and `Time` are handled.
* Move types to the top level `ActiveRecord` namespaceSean Griffin2014-05-271-0/+27
`ActiveRecord::ConnectionAdapters::Type::Value` => `ActiveRecord::Type::Value`