Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
788bd308
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
788bd308
编写于
4月 08, 2011
作者:
J
Jon Leighton
提交者:
Aaron Patterson
4月 12, 2011
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ActiveRecord::Base.scopes hash is not needed
上级
8572ae66
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
4 addition
and
29 deletion
+4
-29
activerecord/lib/active_record/named_scope.rb
activerecord/lib/active_record/named_scope.rb
+4
-16
activerecord/lib/active_record/relation.rb
activerecord/lib/active_record/relation.rb
+0
-2
activerecord/test/cases/named_scope_test.rb
activerecord/test/cases/named_scope_test.rb
+0
-11
未找到文件。
activerecord/lib/active_record/named_scope.rb
浏览文件 @
788bd308
...
...
@@ -9,11 +9,6 @@ module ActiveRecord
module
NamedScope
extend
ActiveSupport
::
Concern
included
do
class_attribute
:scopes
self
.
scopes
=
{}
end
module
ClassMethods
# Returns an anonymous \scope.
#
...
...
@@ -135,27 +130,20 @@ def scope(name, scope_options = {})
scope_proc
=
lambda
do
|*
args
|
options
=
scope_options
.
respond_to?
(
:call
)
?
scope_options
.
call
(
*
args
)
:
scope_options
options
=
scoped
.
apply_finder_options
(
options
)
if
options
.
is_a?
(
Hash
)
relation
=
if
options
.
is_a?
(
Hash
)
scoped
.
apply_finder_options
(
options
)
elsif
options
scoped
.
merge
(
options
)
else
scoped
end
relation
=
scoped
.
merge
(
options
)
extension
?
relation
.
extending
(
extension
)
:
relation
end
self
.
scopes
=
self
.
scopes
.
merge
name
=>
scope_proc
singleton_class
.
send
(
:redefine_method
,
name
,
&
scopes
[
name
])
singleton_class
.
send
(
:redefine_method
,
name
,
&
scope_proc
)
end
protected
def
valid_scope_name?
(
name
)
if
!
scopes
[
name
]
&&
respond_to?
(
name
,
true
)
if
respond_to?
(
name
,
true
)
logger
.
warn
"Creating scope :
#{
name
}
. "
\
"Overwriting existing method
#{
self
.
name
}
.
#{
name
}
."
end
...
...
activerecord/lib/active_record/relation.rb
浏览文件 @
788bd308
...
...
@@ -416,8 +416,6 @@ def with_default_scope #:nodoc:
def
method_missing
(
method
,
*
args
,
&
block
)
if
Array
.
method_defined?
(
method
)
to_a
.
send
(
method
,
*
args
,
&
block
)
elsif
@klass
.
scopes
[
method
]
merge
(
@klass
.
send
(
method
,
*
args
,
&
block
))
elsif
@klass
.
respond_to?
(
method
)
scoping
{
@klass
.
send
(
method
,
*
args
,
&
block
)
}
elsif
arel
.
respond_to?
(
method
)
...
...
activerecord/test/cases/named_scope_test.rb
浏览文件 @
788bd308
...
...
@@ -58,17 +58,6 @@ def test_respond_to_respects_include_private_parameter
assert
Topic
.
approved
.
respond_to?
(
:tables_in_string
,
true
)
end
def
test_subclasses_inherit_scopes
assert
Topic
.
scopes
.
include?
(
:base
)
assert
Reply
.
scopes
.
include?
(
:base
)
assert_equal
Reply
.
find
(
:all
),
Reply
.
base
end
def
test_classes_dont_inherit_subclasses_scopes
assert
!
ActiveRecord
::
Base
.
scopes
.
include?
(
:base
)
end
def
test_scopes_with_options_limit_finds_to_those_matching_the_criteria_specified
assert
!
Topic
.
find
(
:all
,
:conditions
=>
{
:approved
=>
true
}).
empty?
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录