aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/aggregations.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.
* Remove `ActiveSupport::Concern` from `ActiveRecord::Aggregations`Ryuta Kamizono2018-06-261-2/+0
| | | | | `include Aggregations` no longer needs to invoke `extend Aggregations::ClassMethods` since 657060b.
* Lazily add `Aggregations` to `composed_of` modelsAaron Patterson2018-06-251-0/+4
| | | | | | | | `composed_of` is a fairly rare method to call on models. This commit adds the `Aggregations` module to models that call `composed_of` so that models that *don't* call `composed_of` don't need to instantiate the `aggregation_cache` hash. This saves one hash allocation per model instance that doesn't use `composed_of`
* Fix the example of 'finding records by a value object' (#31818)Bogdan2018-01-291-2/+2
| | | | | | | | | This example was added in abdf546ad6d02ecb95766e73cd3c645a48c954de but was inconsistent with `composed_of :balance` definition in the 'Customer'. [Ryuta Kamizono & bogdanvlviv] [ci skip]
* Revert "Merge pull request #23256 from pauloancheta/master"Ryuta Kamizono2018-01-291-1/+1
| | | | | | | | | | | | | This reverts commit 755f7b58953c25790eea0574ff8928033ded2d88, reversing changes made to 35db4603095e8ccc0a92d925a42d4b3d9462580f. Originally `mapping: %w(balance amount)` is correct mapping example. Closes #31346. [Ryuta Kamizono & bogdanvlviv] [ci skip]
* Remove unused/missing `to_money` converter in the test/docRyuta Kamizono2018-01-291-2/+1
|
* 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
|
* No need to nodoc private methodsAkira Matsuda2016-12-241-2/+2
|
* Add missing `+` around a some literals.bogdanvlviv2016-10-271-1/+1
| | | | | | Mainly around `nil` [ci skip]
* Fix broken comments indentation caused by rubocop auto-correct [ci skip]Ryuta Kamizono2016-09-141-155/+155
| | | | | | 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.
* Add three new rubocop rulesRafael Mendonça França2016-08-161-2/+2
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-87/+87
|
* Don't assume all hashes are from multiparameter assignment in `composed_of`Sean Griffin2016-08-051-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | So this bug is kinda funky. The code path is basically "if we weren't passed an instance of the class we compose to, and we have a converter, call that". Ignoring the hash case for a moment, everything after that was roughly intended to be the "else" clause, meaning that we are expected to have an instance of the class we compose to. Really, we should be blowing up in that case, as we can give a much better error message than what they user will likely get (e.g. `NameError: No method first for String` or something). Still, Ruby is duck typed, so if the object you're assigning responds to the same methods as the type you compose to, knock yourself out. The hash case was added in 36e9be8 to remove a bunch of special cased code from multiparameter assignment. I wrongly assumed that the only time we'd get a hash there is in that case. Multiparameter assignment will construct a very specific hash though, where the keys are integers, and we will have a set of keys covering `1..part.size` exactly. I'm pretty sure this could actually be passed around as an array, but that's a different story. Really I should convert this to something like `class MultiParameterAssignment < Hash; end`, which I might do soon. However for a change that I'm willing to backport to 4-2-stable, this is what I want to go with for the time being. Fixes #25978
* Ensure hashes can be passed to attributes using `composed_of`Sean Griffin2016-05-311-4/+5
| | | | | | | | | | | This behavior was broken by 36e9be85. When the value is assigned directly, either through mass assignment or directly assigning a hash, the hash gets passed through to this writer method directly. While this is intended to handle certain cases, when an explicit converter has been provided, we should continue to use that instead. The positioning of the added guard caused the new behavior to override that case. Fixes #25210
* reflect mapping to match initializePaulo Ancheta2016-01-251-1/+1
|
* applies new doc guidelines to Active Record.Yves Senn2015-10-141-11/+11
| | | | | | | | | | | | | | | | | | | 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
* [ci skip] Replace double spaces with single spaceyui-knk2015-09-171-1/+1
|
* Fix NetAddr link [ci skip]amitkumarsuroliya2015-05-201-1/+1
|
* Do not test, document or use a private API methodRafael Mendonça França2015-02-201-5/+0
| | | | These methods are nodoc so we should not document them.
* Merge pull request #16989 from Empact/reload-cache-clearRafael Mendonça França2015-02-201-3/+20
|\ | | | | | | Isolate access to @associations_cache and @aggregations_cache to the Associations and Aggregations modules, respectively.
| * Isolate access to @associations_cache and @aggregations cache to the ↵Ben Woosley2014-09-281-3/+20
| | | | | | | | | | | | | | | | Associations and Aggregations modules, respectively. This includes replacing the `association_cache` accessor with a more limited `association_cached?` accessor and making `clear_association_cache` and `clear_aggregation_cache` private.
* | Push multi-parameter assignement into the typesSean Griffin2015-02-071-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | This allows us to remove `Type::Value#klass`, as it was only used for multi-parameter assignment to reach into the types internals. The relevant type objects now accept a hash in addition to their previous accepted arguments to `type_cast_from_user`. This required minor modifications to the tests, since previously they were relying on the fact that mulit-parameter assignement was reaching into the internals of time zone aware attributes. In reaility, changing those properties at runtime wouldn't change the accessor methods for all other forms of assignment.
* | Improve the performance of reading attributesSean Griffin2014-11-181-2/+2
|/ | | | | | | We added a comparison to "id", and call to `self.class.primary_key` a *lot*. We also have performance hits from `&block` all over the place. We skip the check in a new method, in order to avoid breaking the behavior of `read_attribute`
* Merge pull request #15542 from Gaurav2728/gaurav-remove_shutdown_linkArthur Nogueira Neves2014-06-061-4/+4
|\ | | | | remove rubyforge.org that was shut down [ci skip]
| * remove rubyforge.org that was shut down [ci skip]Gaurav Sharma2014-06-061-4/+4
| |
* | Remove composed_of special case from multi-parameter attributesSean Griffin2014-06-061-0/+4
|/ | | | | As we move towards removing the `klass` method from `column`, the else clause as it stands right now will become the only case.
* Use destructured arguments when looping through pairsSean Griffin2014-05-171-4/+4
| | | | Minor refactoring of looping behavior for aggregation
* Remove conditional adding a new methodRafael Mendonça França2013-09-111-1/+1
| | | | | | At the point we want to add the reflection we already know the reflection is of the AggregateReflection type so we can call a specific method
* factory methods should not have side effects.Aaron Patterson2013-07-231-1/+2
| | | | Move model mutation to the methods that are called on the model.
* AR::Base does not need to know how to create reflection objectsAaron Patterson2013-07-221-1/+1
|
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2013-01-091-1/+1
|\ | | | | | | | | Conflicts: guides/source/getting_started.md
| * remove meaningless use of Relation#allAkira Matsuda2013-01-031-1/+1
| | | | | | | | particularly, `all(options)` would warn
* | remove meaningless AS::FrozenObjectErrorAkira Matsuda2013-01-021-1/+1
|/
* 1.9 hash syntax changesAvnerCohen2012-11-081-18/+18
|
* Revert "Removing composed_of from ActiveRecord."Rafael Mendonça França2012-07-271-0/+261
| | | | | | | | | | | This reverts commit 14fc8b34521f8354a17e50cd11fa3f809e423592. Reason: we need to discuss a better path from this removal. Conflicts: activerecord/lib/active_record/reflection.rb activerecord/test/cases/base_test.rb activerecord/test/models/developer.rb
* Removing composed_of from ActiveRecord.Steve Klabnik2012-06-181-261/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This feature adds a lot of complication to ActiveRecord for dubious value. Let's talk about what it does currently: class Customer < ActiveRecord::Base composed_of :balance, :class_name => "Money", :mapping => %w(balance amount) end Instead, you can do something like this: def balance @balance ||= Money.new(value, currency) end def balance=(balance) self[:value] = balance.value self[:currency] = balance.currency @balance = balance end Since that's fairly easy code to write, and doesn't need anything extra from the framework, if you use composed_of today, you'll have to add accessors/mutators like that. Closes #1436 Closes #2084 Closes #3807
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-05-231-3/+3
|\
| * Revert "Remove blank trailing comments"Vijay Dev2012-05-231-0/+2
| | | | | | | | | | | | | | | | | | | | This reverts commit fa6d921e11363e9b8c4bc10f7aed0b9faffdc33a. Reason: Not a fan of such massive changes. We usually close such changes if made to Rails master as a pull request. Following the same principle here and reverting. [ci skip]
| * Remove blank trailing commentsHenrik Hodne2012-05-201-2/+0
| | | | | | | | | | | | | | For future reference, this is the regex I used: ^\s*#\s*\n(?!\s*#). Replace with the first match, and voilà! Note that the regex matches a little bit too much, so you probably want to `git add -i .` and go through every single diff to check if it actually should be changed.
| * Revert typoOscar Del Ben2012-05-191-1/+1
| |
| * TypoOscar Del Ben2012-05-191-4/+4
| |
* | Refactor aggregation writer methodCarlos Antonio da Silva2012-05-211-4/+3
| | | | | | | | Only constantize class_name once.
* | Merge pull request #6143 from senny/composed_of_converter_returns_nilAaron Patterson2012-05-211-7/+8
|\ \ | |/ |/| allow the :converter Proc form composed_of to return nil
| * allow the :converter Proc form composed_of to return nilYves Senn2012-05-031-7/+8
| | | | | | | | | | | | | | This makes it possible to filter invalid input values before they are passed into the value-object (like empty strings). This behaviour is only relevant if the :allow_nil options is set to true. Otherwise you will get the resulting NoMethodError.
* | missing 'with'Hrvoje Šimić2012-05-111-1/+1
| |
* | Add empty rows to improve readability. [ci skip]Edward Tsech2012-05-011-0/+2
| |
* | Add few lines to describe how aggregation part caching works. [ci skip]Edward Tsech2012-05-011-0/+4
| |
* | simpler wording and explanationsHrvoje Šimić2012-05-011-3/+3
| |