aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/type/serialized.rb
Commit message (Collapse)AuthorAgeFilesLines
* Enable `Layout/EmptyLinesAroundAccessModifier` copRyuta Kamizono2019-06-131-1/+0
| | | | | | | | | | | We sometimes say "✂️ newline after `private`" in a code review (e.g. https://github.com/rails/rails/pull/18546#discussion_r23188776, https://github.com/rails/rails/pull/34832#discussion_r244847195). Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style `EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059). That cop and enforced style will reduce the our code review cost.
* Fix force equality checking not to break the serialized attribute with ArrayRyuta Kamizono2018-06-061-0/+4
| | | | Context: https://github.com/rails/rails/commit/43ef00e5d7a55ad79bc840276d33cb70f1f5dde5#commitcomment-29256140
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Suppress deprecation warning `implementing to_yaml is deprecated`Fumiaki MATSUSHIMA2017-02-151-0/+2
|
* Indicate action that failed in YamlColumnKir Shatrov2017-02-051-1/+1
|
* Revert "Made ActiveRecord consistently use ActiveRecord::Type (not"Sean Griffin2016-10-231-2/+2
| | | | | | This reverts commit 671eb742eec77b5c8281ac2a2e3976ef32a6e424. This is not a change we would like moving forward.
* Made ActiveRecord consistently use ActiveRecord::Type (notIain Beeston2016-10-031-2/+2
| | | | | | | | ActiveModel::Type) Some code was previously referring to ActiveModel::Type::*. This could cause issues in the future if any of the ActiveRecord::Type classes were overridden in the future.
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-7/+7
|
* Fix false positive mutation detection when JSON is used with serializeSean Griffin2016-05-121-1/+7
| | | | | | | | | | | | | When looking for mutation, we compare the serialized version of the value to the before_type_cast form. `Type::Serialized` was breaking this contract by passing the already serialized attribute to the subtype's mutation detection. This never manifested previously, as all mutable subtypes either didn't do anything in their `serialize` method, or had a way to detect double serialization (e.g. `is_a?(String)`). However, now that JSON types can handle string primitives, we need to avoid double serialization. Fixes #24993.
* Clean up the implementation of AR::DirtySean Griffin2015-09-241-0/+6
| | | | | | | | | | | | | 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
* Move ActiveRecord::Type to ActiveModelKir Shatrov2015-09-211-2/+2
| | | | The first step of bringing typecasting to ActiveModel
* Provide a more truthful #inspectMatthew Draper2015-03-231-0/+4
| | | | | | This is obviously all very internal, but sometimes you have to look at it... and when you do, it'll save a lot of confusion if it doesn't lie about its identity.
* Make sure to persist a newly-nil serialized valueMatthew Draper2015-03-231-1/+3
| | | | | | | The subtype will (quite reasonably) ignore the possibility that it has `changed_in_place?` by becoming nil. Fixes #19467
* `type_cast_for_database` -> `serialize`Sean Griffin2015-02-171-2/+2
|
* `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.
* rm `ActiveRecord::Type::Decorator`Sean Griffin2015-02-071-11/+0
| | | | | | | It only existed to make sure the subclasses of `Delegator` were YAML serializable. As of Ruby 2.2, these are YAML dumpable by default, as it includes https://github.com/tenderlove/psych/commit/2a4d9568f7d5d19c00231cf48eb855cc45ec3394
* Don't treat `nil` as changed in serialized typesSean Griffin2014-12-231-1/+1
| | | | | | | We were ignoring the `default_value?` escape clause in the serialized type, which caused the default value to always be treated as changed. Fixes #18169
* Use `DelegateClass` instead of `SimpleDelegator` for type decoratorsSean Griffin2014-11-141-1/+1
| | | | There is a significant performance difference between the two. Closes
* Allow YAML serialization when using TZ aware attributesSean Griffin2014-09-171-3/+3
|
* Correctly detect mutation on serialized columns mapping to binarySean Griffin2014-08-271-0/+5
| | | | Fixes #16701
* Rename method for clarityCarlos Antonio da Silva2014-07-311-3/+3
| | | | Ruby generally does not use the is_* prefix on predicate methods.
* Remove `serialized?` from the type interfaceSean Griffin2014-06-131-4/+0
|
* Detect in-place changes on mutable AR attributesSean Griffin2014-06-131-4/+2
| | | | | | We have several mutable types on Active Record now. (Serialized, JSON, HStore). We need to be able to detect if these have been modified in place.
* Keep the types of virtual columns after yaml serializationSean Griffin2014-06-101-0/+11
| | | | | On MySQL and PostgreSQL, the adapter does not type cast virtual columns for us.
* Rename `type_cast` to `type_cast_from_database`Sean Griffin2014-06-091-2/+2
| | | | | | | | In some cases there is a difference between the two, we should always be doing one or the other. For convenience, `type_cast` is still a private method on type, so new types that do not need different behavior don't need to implement two methods, but it has been moved to private so it cannot be used accidentally.
* Make `_before_type_cast` actually be before type castSean Griffin2014-06-091-3/+5
| | | | | | | | | | | | | - The following is now true for all types, all the time - `model.attribute_before_type_cast == given_value` - `model.attribute == model.save_and_reload.attribute` - `model.attribute == model.dup.attribute` - `model.attribute == YAML.load(YAML.dump(model)).attribute` - Removes the remaining types implementing `type_cast_for_write` - Simplifies the implementation of time zone aware attributes - Brings tz aware attributes closer to being implemented as an attribute decorator - Adds additional point of control for custom types
* Do not type cast twice on attribute assignmentSean Griffin2014-06-071-4/+0
| | | | | | | | | | | | | The definition of `write_attribute` in dirty checking ultimately leads to the columns calling `type_cast` on the value to perform the comparison. However, this is a potentially expensive computation that we cache when it occurs in `read_attribute`. The only case that we need the non-type-cast form is for numeric, so we pass that through as well (something I'm looking to remove in the future). This also reduces the number of places that manually access various stages in an attribute's type casting lifecycle, which will aid in one of the larger refactorings that I'm working on.
* serialized Type should delegate `type_cast_for_write` to underlying TypeYves Senn2014-06-061-1/+1
| | | | | | | This adds a regression test for #14411, which was fixed by #15503. Closes #14411 Closes #14595
* Refactor determination of whether the field has changedSean Griffin2014-06-031-0/+4
| | | | | The types know more about what is going on than the dirty module. Let's ask them!
* Remove most code related to serialized propertiesSean Griffin2014-06-011-24/+11
| | | | | | | | | | | Nearly completely implemented in terms of custom properties. `_before_type_cast` now stores the raw serialized string consistently, which removes the need to keep track of "state". The following is now consistently true: - `model.serialized == model.reload.serialized` - A model can be dumped and loaded infinitely without changing - A model can be saved and reloaded infinitely without changing
* Move `type_cast_for_write` behavior over to the serialized type objectSean Griffin2014-05-291-3/+32
|
* Refactor serialized types to be partially defined as custom propertiesSean Griffin2014-05-291-0/+28
Many of the methods defined in `AttributeMethods::Serialization` can be refactored onto this type as well, but this is a reasonable small step. Removes the `Type` class, and the need for `decorate_columns` to handle serialized types.