aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/type
Commit message (Collapse)AuthorAgeFilesLines
...
* | Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-1/+1
|/
* Merge pull request #24571 from raimo/patch-1Sean Griffin2016-10-041-0/+9
|\ | | | | Print the proper ::Float::INFINITY value when used as a default value
| * Print the proper ::Float::INFINITY value when used as a default valueRaimo Tuisku2016-05-231-0/+9
| | | | | | | | Addresses https://github.com/rails/rails/issues/22396
* | Fix broken comments indentation caused by rubocop auto-correct [ci skip]Ryuta Kamizono2016-09-143-6/+6
| | | | | | | | | | | | All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772. But comments was still kept absolute position. This commit aligns comments with method definitions for consistency.
* | Fix Remaining Case-In-Assignment Statement FormattingAlex Kitchens2016-09-061-12/+13
| | | | | | | | | | | | | | | | | | Recently, the Rails team made an effort to keep the source code consistent, using Ruboco (bb1ecdcc677bf6e68e0252505509c089619b5b90 and below). Some of the case statements were missed. This changes the case statements' formatting and is consistent with changes in 810dff7c9fa9b2a38eb1560ce0378d760529ee6b and db63406cb007ab3756d2a96d2e0b5d4e777f8231.
* | apply case-in-assignment patternXavier Noria2016-09-022-11/+13
| |
* | RuboCop is 100% green :tada:Xavier Noria2016-09-022-2/+2
| |
* | code gardening: removes redundant selfsXavier Noria2016-08-081-1/+1
| | | | | | | | | | | | | | | | | | A few have been left for aesthetic reasons, but have made a pass and removed most of them. Note that if the method `foo` returns an array, `foo << 1` is a regular push, nothing to do with assignments, so no self required.
* | applies remaining conventions across the projectXavier Noria2016-08-061-9/+9
| |
* | normalizes indentation and whitespace across the projectXavier Noria2016-08-0615-182/+182
| |
* | applies new string literal convention in activemodel/libXavier Noria2016-08-068-12/+12
| | | | | | | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* | systematic revision of =~ usage in AMoXavier Noria2016-07-241-1/+1
| |
* | [ci skip] add class level documentation to ActiveModel::Type::BooleanDavid Elliott2016-07-111-2/+13
| | | | | | | | add documentation of the behaviors of type coercion at the class level
* | Fix `Type::Date#serialize` to return a date object correctlyRyuta Kamizono2016-06-161-0/+4
| | | | | | | | | | | | | | | | Currently `Type::Date#serialize` does not cast a value to a date object. It should be cast to a date object for finding by date column correctly working. Fixes #25354.
* | Change RangeError to a more specific ActiveModel::RangeErrorChristian Blais2016-05-031-1/+1
|/ | | | | | The should make it easier for apps to rescue ActiveModel specific errors without the need to wrap all method calls with a generic rescue RangeError.
* Apply scale before precision when coercing floats to decimalSean Griffin2016-03-241-2/+10
| | | | | | | | | | | | | | | | Since precision is always larger than scale, it can actually change rounding behavior. Given a precision of 5 and a scale of 3, when you apply the precision of 5 to `1.25047`, the result is `1.2505`, which when the scale is applied would be `1.251` instead of the expected `1.250`. This issue appears to only occur with floats, as scale doesn't apply to other numeric types, and the bigdecimal constructor actually ignores precision entirely when working with strings. There's no way we could handle this for the "unknown object which responds to `to_d`" case, as we can't assume an interface for applying the scale. Fixes #24235
* Refactor tz aware types, add support for PG rangesSean Griffin2016-01-081-0/+4
| | | | | | | | | | | | | | | | | This is an alternate implementation to #22875, that generalizes a lot of the logic that type decorators are going to need, in order to have them work with arrays, ranges, etc. The types have the ability to map over a value, with the default implementation being to just yield that given value. Array and Range give more appropriate definitions. This does not automatically make ranges time zone aware, as they need to be added to the `time_zone_aware` types config, but we could certainly make that change if we feel it is appropriate. I do think this would be a breaking change however, and should at least have a deprecation cycle. Closes #22875. /cc @matthewd
* Take UTC offset into account when assigning string value to time attribute.Andrey Novikov2016-01-051-1/+1
|
* Use a bind param for `LIMIT` and `OFFSET`Sean Griffin2015-12-141-0/+5
| | | | | | | | | | | | | | | We currently generate an unbounded number of prepared statements when `limit` or `offset` are called with a dynamic argument. This changes `LIMIT` and `OFFSET` to use bind params, eliminating the problem. `Type::Value#hash` needed to be implemented, as it turns out we busted the query cache if the type object used wasn't exactly the same object. This drops support for passing an `Arel::Nodes::SqlLiteral` to `limit`. Doing this relied on AR internals, and was never officially supported usage. Fixes #22250.
* Avoid dummy_time_value to add "2000-01-01" twiceYasuo Honda2015-11-301-1/+5
|
* All strings returned by `ImmutableString` should be frozenSean Griffin2015-10-152-11/+7
| | | | | | | I seriously don't even know why we handle booleans, but those strings should technically be frozen. Additionally, we don't need to actually check the class in the mutable string type, since the `cast_value` function will always return a string.
* Add an immutable string type to opt out of string dupingSean Griffin2015-10-152-20/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This type adds an escape hatch to apps for which string duping causes unacceptable memory growth. The reason we are duping them is in order to detect mutation, which was a feature added to 4.2 in #15674. The string type was modified to support this behavior in #15788. Memory growth is really only a concern for string types, as it's the only mutable type where the act of coersion does not create a new object regardless (as we're usually returning an object of a different class). I do feel strongly that if we are going to support detecting mutation, we should do it universally for any type which is mutable. While it is less common and ideomatic to mutate strings than arrays or hashes, there shouldn't be rules or gotchas to understanding our behavior. However, I also appreciate that for apps which are using a lot of string columns, this would increase the number of allocations by a large factor. To ensure that we keep our contract, if you'd like to opt out of mutation detection on strings, you'll also be option out of mutation of those strings. I'm not completely married to the thought that strings coming out of this actually need to be frozen -- and I think the name is correct either way, as the purpose of this is to provide a string type which does not detect mutation. In the new implementation, I'm only overriding `cast_value`. I did not port over the duping in `serialize`. I cannot think of a reason we'd need to dup the string there, and the tests pass without it. Unfortunately that line was introduced at a time where I was not nearly as good about writing my commit messages, so I have no context as to why I added it. Thanks past Sean. You are a jerk.
* Clean up the implementation of AR::DirtySean Griffin2015-09-242-0/+11
| | | | | | | | | | | | | This moves a bit more of the logic required for dirty checking into the attribute objects. I had hoped to remove the `with_value_from_database` stuff, but unfortunately just calling `dup` on the attribute objects isn't enough, since the values might contain deeply nested data structures. I think this can be cleaned up further. This makes most dirty checking become lazy, and reduces the number of object allocations and amount of CPU time when assigning a value. This opens the door (but doesn't quite finish) to improving the performance of writes to a place comparable to 4.1
* Fixed taking precision into count when assigning a value to timestamp attributeBogdan Gusiev2015-09-232-9/+12
| | | | | | | | | | | | | | | | | Timestamp column can have less precision than ruby timestamp In result in how big a fraction of a second can be stored in the database. m = Model.create! m.created_at.usec == m.reload.created_at.usec # => false # due to different seconds precision in Time.now and database column If the precision is low enough, (mysql default is 0, so it is always low enough by default) the value changes when model is reloaded from the database. This patch fixes that issue ensuring that any timestamp assigned as an attribute is converted to column precision under the attribute.
* Require dependencies from stdlib in the Decimal typeSean Griffin2015-09-211-0/+2
| | | | | | | In Active Record, it appears these were either autoloaded, which actually was likely due to test ordering since the method `Float#to_d` wouldn't trigger it. This makes it explicit, and unlikely to fail in the future.
* Move the appropriate type tests to the Active Model suiteSean Griffin2015-09-211-2/+8
| | | | | | | | | Any tests for a type which is not overridden by Active Record, and does not test the specifics of the attributes API interacting in more complex ways have no reason to be in the Active Record suite. Doing this revealed that the implementation of the date and time types in AM was actually completely broken, and incapable of returning any value other than `nil`.
* Simplify the implementation of Active Model's type registrySean Griffin2015-09-211-97/+10
| | | | | | | | | | | | | | | Things like decorations, overrides, and priorities only matter for Active Record, so the Active Model registry can be implemented much more simply. At this point, I wonder if having Active Record's registry inherit from Active Model's is even worth the trouble? The Active Model class was also missing test cases, which have been backfilled. This removes the error when two types are registered with the same name, but given that Active Model is meant to be significantly more generic, I do not think this is an issue for now. If we want, we can raise an error at the point that someone tries to register it.
* Various stylistic nitpicksSean Griffin2015-09-211-4/+3
| | | | | | | We do not need to require each file from AM individually, the type module does that for us. Even if the classes are extremely small right now, I'd rather keep any custom classes needed by AR in their own files, as they can easily have more complex changes in the future.
* `TypeMap` and `HashLookupTypeMap` shouldn't be in Active ModelSean Griffin2015-09-212-87/+0
| | | | | | These are used by the connection adapters to convert SQL type information into the appropriate type object, and makes no sense outside of the context of Active Record
* Move ActiveRecord::Type to ActiveModelKir Shatrov2015-09-2122-0/+928
The first step of bringing typecasting to ActiveModel