aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods/before_type_cast.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.
* Avoid method call if `@transaction_state` is not finalizedRyuta Kamizono2019-04-211-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Method call in Ruby is a bit slow. This makes attribute access 10% faster by avoiding method call (`sync_with_transaction_state`). Before (96cf7e0e): ``` Warming up -------------------------------------- user.id 131.291k i/100ms user['id'] 91.786k i/100ms user.name 151.605k i/100ms user['name'] 92.664k i/100ms user.changed? 17.772k i/100ms user.saved_changes? 23.909k i/100ms Calculating ------------------------------------- user.id 1.988M (± 7.0%) i/s - 9.978M in 5.051474s user['id'] 1.155M (± 5.8%) i/s - 5.783M in 5.022672s user.name 2.450M (± 4.3%) i/s - 12.280M in 5.021234s user['name'] 1.263M (± 2.1%) i/s - 6.394M in 5.066638s user.changed? 175.070k (±13.3%) i/s - 853.056k in 5.011555s user.saved_changes? 259.114k (±11.8%) i/s - 1.267M in 5.001260s ``` After (this change): ``` Warming up -------------------------------------- user.id 137.625k i/100ms user['id'] 96.054k i/100ms user.name 156.379k i/100ms user['name'] 94.795k i/100ms user.changed? 18.172k i/100ms user.saved_changes? 24.337k i/100ms Calculating ------------------------------------- user.id 2.201M (± 0.5%) i/s - 11.010M in 5.002955s user['id'] 1.320M (± 1.0%) i/s - 6.628M in 5.021293s user.name 2.677M (± 1.6%) i/s - 13.449M in 5.024399s user['name'] 1.314M (± 1.8%) i/s - 6.636M in 5.051444s user.changed? 190.588k (±11.1%) i/s - 944.944k in 5.065848s user.saved_changes? 262.782k (±12.1%) i/s - 1.290M in 5.028080s ```
* Fix dirty tracking after rollback.Ryuta Kamizono2019-04-161-0/+3
| | | | | | | | | | | | | | | | | Currently the rollback only restores primary key value, `new_record?`, `destroyed?`, and `frozen?`. Since the `save` clears current dirty attribute states, retrying save after rollback will causes no change saved if partial writes is enabled (by default). This makes `remember_transaction_record_state` remembers original values then restores dirty attribute states after rollback. Fixes #15018. Fixes #30167. Fixes #33868. Fixes #33443. Closes #33444. Closes #34504.
* Improve wording of commentsChris Salzberg2019-04-131-1/+1
| | | | | | Most of the time, these methods are called from actual methods defined from columns in the schema, not from method_missing, so the current wording is misleading.
* 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
|
* Fix broken comments indentation caused by rubocop auto-correct [ci skip]Ryuta Kamizono2016-09-141-1/+1
| | | | | | 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.
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-6/+6
|
* applies new doc guidelines to Active Record.Yves Senn2015-10-141-1/+1
| | | | | | | | | | | | | | | | | | | The focus of this change is to make the API more accessible. References to method and classes should be linked to make it easy to navigate around. This patch makes exzessiv use of `rdoc-ref:` to provide more readable docs. This makes it possible to document `ActiveRecord::Base#save` even though the method is within a separate module `ActiveRecord::Persistence`. The goal here is to bring the API closer to the actual code that you would write. This commit only deals with Active Record. The other gems will be updated accordingly but in different commits. The pass through Active Record is not completely finished yet. A follow up commit will change the spots I haven't yet had the time to update. /cc @fxn
* Only use the `_before_type_cast` in the form when from user inputSean Griffin2015-01-141-0/+5
| | | | | | While we don't want to change the form input when validations fail, blindly using `_before_type_cast` will cause the input to display the wrong data for any type which does additional work on database values.
* Merge pull request #15846 from sgrif/sg-attributes-before-type-castRafael Mendonça França2014-06-261-1/+1
|\ | | | | | | | | | | | | | | Move `attributes_before_type_cast` to `AttributeSet` Conflicts: activerecord/lib/active_record/attribute_set.rb activerecord/test/cases/attribute_set_test.rb
| * Move `attributes_before_type_cast` to `AttributeSet`Sean Griffin2014-06-211-1/+1
| |
* | Return a null object from `AttributeSet#[]`Sean Griffin2014-06-201-3/+1
|/
* Introduce an Attribute object to handle the type casting danceSean Griffin2014-06-131-2/+4
| | | | | | | | | | | | | | | There's a lot more that can be moved to these, but this felt like a good place to introduce the object. Plans are: - Remove all knowledge of type casting from the columns, beyond a reference to the cast_type - Move type_cast_for_database to these objects - Potentially make them mutable, introduce a state machine, and have dirty checking handled here as well - Move `attribute`, `decorate_attribute`, and anything else that modifies types to mess with this object, not the columns hash - Introduce a collection object to manage these, reduce allocations, and not require serializing the types
* Rename attribute related instance variables to better express intentSean Griffin2014-05-301-2/+2
| | | | | | | | | `@attributes` was actually used for `_before_type_cast` and friends, while `@attributes_cache` is the type cast version (and caching is the wrong word there, but I'm working on removing the conditionals around that). I opted for `@raw_attributes`, because `_before_type_cast` is also semantically misleading. The values in said hash are in the state given by the form builder or database, so raw seemed to be a good word.
* read_attribute_before_type_cast should accept symbolNeeraj Singh2013-05-111-1/+2
|
* Fix code example in AR::AttributeMethods::BeforeTypeCast.Hendy Tanata2012-10-221-1/+1
|
* add docs to AR::AttributeMethods::BeforeTypeCast [ci skip]Francesco Rodriguez2012-10-211-0/+23
|
* fix typo and improve example [ci skip]Francesco Rodriguez2012-10-211-1/+3
|
* update AR::AttributeMethods::BeforeTypeCast docs [ci skip]Francesco Rodriguez2012-10-211-0/+18
|
* move id_before_type_cast to PrimaryKey moduleSergey Nartimov2012-02-161-5/+1
|
* Fix indentation hereSantiago Pastorino2010-12-041-7/+8
|
* attributes_before_type_cast are just the value of @attributesSantiago Pastorino2010-12-041-1/+1
|
* No need to use inject here, use map instead.Emilio Tagua2010-09-221-4/+1
| | | | Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
* Revert "Refactoring attributes/types" [#3348 state:open]Pratik Naik2010-01-221-3/+10
| | | | | | | | | | | | | | | | | This reverts commit f936a1f100e75082081e782e5cceb272885c2df7. Conflicts: activerecord/lib/active_record.rb activerecord/lib/active_record/base.rb Revert "Fixed: #without_typecast should only disable typecasting on the duplicated attributes" [#3387 state:open] This reverts commit 2831996483c6a045f1f38d8030256eb58d9771c3. Reason : It's not generating attribute methods properly, making object.column 5x slower.
* Refactoring attributes/types [#3348 state:resolved]Eric Chapweske2009-10-171-10/+3
| | | | Signed-off-by: Joshua Peek <josh@joshpeek.com>
* Don't define id_before_type_cast, just let it be generated on its ownJoshua Peek2009-07-301-5/+5
|
* Move id attribute methods into their related concernJoshua Peek2009-07-301-0/+12
|
* Concernify AR AttributeMethodsJoshua Peek2009-07-301-0/+21