1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

20 commits

Author SHA1 Message Date
Xavier Noria
80e66cc4d9 normalizes indentation and whitespace across the project 2016-08-06 20:16:27 +02:00
Xavier Noria
4df2b779dd applies new string literal convention in activerecord/lib
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 18:26:45 +02:00
Matthew Draper
8ce0175d50 Active scopes apply to child classes, though not parents/siblings
While the commit message (and changelog example) in
5e0b555b45 talked about sibling classes,
the added test had a child ignore its parent's scoping, which seems less
reasonable.
2016-01-12 05:43:58 +10:30
Yves Senn
428d47adfe applies new doc guidelines to Active Record.
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
2015-10-14 17:40:00 +02:00
Yves Senn
215e128ddc add missing :nodoc: to ActiveRecord::Scoping. [ci skip] 2015-10-14 09:45:56 +02:00
Ben Woosley
c1deb81cd0 Isolate access to .default_scopes in ActiveRecord::Scoping::Default
Instead use .scope_attributes? consistently in ActiveRecord to check whether
there are attributes currently associated with the scope.

Move the implementation of .scope_attributes? and .scope_attributes to
ActiveRecord::Scoping because they don't particularly have to do specifically
with Named scopes and their only dependency, in the case of
.scope_attributes?, and only caller, in the case of .scope_attributes is
contained in Scoping.
2015-03-12 01:22:39 -07:00
Sean Griffin
5e0b555b45 current_scope shouldn't pollute sibling STI classes
It looks like the only reason `current_scope` was thread local on
`base_class` instead of `self` is to ensure that when we call a named
scope created with a proc on the parent class, it correctly uses the
default scope of the subclass. The reason this wasn't happening was
because the proc captured `self` as the parent class, and we're not
actually defining a real method. Using `instance_exec` fixes the
problem.

Fixes #18806
2015-02-11 13:46:30 -07:00
Rafael Mendonça França
6931bed1b4 Revert "Merge pull request #14544 from jefflai2/named_scope_sti"
This reverts commit 9a1abedcde, reversing
changes made to c72d6c91a7.

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/test/models/comment.rb

This change break integration with activerecord-deprecated_finders so
I'm reverting until we find a way to make it work with this gem.
2014-05-21 12:15:57 -03:00
Jefferson Lai
9c3afdc327 Fixes Issue #13466.
Changed the call to a scope block to be evaluated with instance_eval.
The result is that ScopeRegistry can use the actual class instead of base_class when
caching scopes so queries made by classes with a common ancestor won't leak scopes.
2014-04-23 17:21:45 -07:00
Keenan Brock
8cbd500035 Move changed_attributes into dirty.rb
Move serialization dirty into serialization.rb
2014-01-22 13:47:34 -05:00
Xavier Noria
e5ef3abdd2 hides the per thread registry instance, and caches singleton methods
Existing code was delegating to the instance with delegate
macro calls, or invoking the instance method to reach
the object and call its instance methods.

But the point is to have a clean class-level interface where
the thread local instance is hidden in the implementation.

References #11c6973.
References #10198.
2013-04-13 17:09:13 +02:00
wangjohn
e12901e423 Changed the ScopeRegistry and the InstrumentationRegistry to use the
PerThreadRegistry module.
2013-04-09 22:27:32 -04:00
wangjohn
a332712503 Delegating the value getter and setters in the ScopeRegistry to the
current ScopeRegister object.
2013-04-08 15:18:14 -04:00
wangjohn
5b945f2685 Grouping thread locals in the ActiveRecord scopes so that the
current_scope and ignore_default_scope locals are brought together under
a registry object.
2013-04-08 13:21:13 -04:00
Jon Leighton
8606a7fbe9 Fix scope chaining + STI
See #9869 and #9929.

The problem arises from the following example:

    class Project < ActiveRecord::Base
      scope :completed, -> { where completed: true }
    end

    class MajorProject < Project
    end

When calling:

    MajorProject.where(tasks_count: 10).completed

This expands to:

    MajorProject.where(tasks_count: 10).scoping {
      MajorProject.completed
    }

However the lambda for the `completed` scope is defined on Project. This
means that when it is called, `self` is Project rather than
MajorProject. So it expands to:

    MajorProject.where(tasks_count: 10).scoping {
      Project.where(completed: true)
    }

Since the scoping was applied on MajorProject, and not Project, this
fails to apply the tasks_count condition.

The solution is to make scoping apply across STI classes. I am slightly
concerned about the possible side-effects of this, but no tests fail and
it seems ok. I guess we'll see.
2013-04-05 13:14:28 +01:00
Carlos Antonio da Silva
2cb576ef36 Refactor to use each_key, remove extra spaces 2013-01-28 23:25:03 -02:00
Xavier Noria
64bc8447c2 load active_support/concern in active_support/rails 2012-08-02 21:59:23 +02:00
Jon Leighton
d242e46781 extract #with_scope and #with_exclusive_scope to active_record_deprecated_finders 2012-04-25 15:45:06 +01:00
Jon Leighton
2b22564c4e Move DefaultScope and NamedScope under Scoping 2011-12-15 20:45:42 +00:00
Jon Leighton
ceb33f8493 Split out most of the AR::Base code into separate modules 🍰 2011-12-15 20:45:37 +00:00