Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
99b607e6
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,发现更多精彩内容 >>
未验证
提交
99b607e6
编写于
3月 13, 2020
作者:
E
Eileen M. Uchitelle
提交者:
GitHub
3月 13, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #38719 from eileencodes/refactor-fetch_attribute
Refactor fetch_attribute
上级
311b94d4
ce7bbc36
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
43 addition
and
26 deletion
+43
-26
activerecord/lib/arel.rb
activerecord/lib/arel.rb
+2
-10
activerecord/lib/arel/nodes/binary.rb
activerecord/lib/arel/nodes/binary.rb
+24
-16
activerecord/lib/arel/nodes/equality.rb
activerecord/lib/arel/nodes/equality.rb
+8
-0
activerecord/lib/arel/nodes/grouping.rb
activerecord/lib/arel/nodes/grouping.rb
+3
-0
activerecord/lib/arel/nodes/node.rb
activerecord/lib/arel/nodes/node.rb
+3
-0
activerecord/lib/arel/nodes/sql_literal.rb
activerecord/lib/arel/nodes/sql_literal.rb
+3
-0
未找到文件。
activerecord/lib/arel.rb
浏览文件 @
99b607e6
...
...
@@ -47,16 +47,8 @@ def self.arel_node?(value) # :nodoc:
end
def
self
.
fetch_attribute
(
value
,
&
block
)
# :nodoc:
case
value
when
Arel
::
Nodes
::
Between
,
Arel
::
Nodes
::
In
,
Arel
::
Nodes
::
NotIn
,
Arel
::
Nodes
::
Equality
,
Arel
::
Nodes
::
NotEqual
,
Arel
::
Nodes
::
LessThan
,
Arel
::
Nodes
::
LessThanOrEqual
,
Arel
::
Nodes
::
GreaterThan
,
Arel
::
Nodes
::
GreaterThanOrEqual
attribute_value
=
value
.
detect_attribute
yield
attribute_value
if
attribute_value
when
Arel
::
Nodes
::
Or
fetch_attribute
(
value
.
left
,
&
block
)
&&
fetch_attribute
(
value
.
right
,
&
block
)
when
Arel
::
Nodes
::
Grouping
fetch_attribute
(
value
.
expr
,
&
block
)
unless
String
===
value
value
.
fetch_attribute
(
&
block
)
end
end
end
activerecord/lib/arel/nodes/binary.rb
浏览文件 @
99b607e6
...
...
@@ -11,14 +11,6 @@ def initialize(left, right)
@right
=
right
end
def
detect_attribute
if
self
.
left
.
is_a?
(
Arel
::
Attributes
::
Attribute
)
self
.
left
elsif
self
.
right
.
is_a?
(
Arel
::
Attributes
::
Attribute
)
self
.
right
end
end
def
initialize_copy
(
other
)
super
@left
=
@left
.
clone
if
@left
...
...
@@ -37,18 +29,34 @@ def eql?(other)
alias
:==
:eql?
end
module
FetchAttribute
def
fetch_attribute
if
left
.
is_a?
(
Arel
::
Attributes
::
Attribute
)
yield
left
elsif
right
.
is_a?
(
Arel
::
Attributes
::
Attribute
)
yield
right
end
end
end
class
Between
<
Binary
;
include
FetchAttribute
;
end
class
NotIn
<
Binary
;
include
FetchAttribute
;
end
class
GreaterThan
<
Binary
;
include
FetchAttribute
;
end
class
GreaterThanOrEqual
<
Binary
;
include
FetchAttribute
;
end
class
NotEqual
<
Binary
;
include
FetchAttribute
;
end
class
LessThan
<
Binary
;
include
FetchAttribute
;
end
class
LessThanOrEqual
<
Binary
;
include
FetchAttribute
;
end
class
Or
<
Binary
def
fetch_attribute
(
&
block
)
left
.
fetch_attribute
(
&
block
)
&&
right
.
fetch_attribute
(
&
block
)
end
end
%w{
As
Assignment
Between
GreaterThan
GreaterThanOrEqual
Join
LessThan
LessThanOrEqual
NotEqual
NotIn
Or
Union
UnionAll
Intersect
...
...
activerecord/lib/arel/nodes/equality.rb
浏览文件 @
99b607e6
...
...
@@ -10,6 +10,14 @@ def operator; :== end
def
invert
Arel
::
Nodes
::
NotEqual
.
new
(
left
,
right
)
end
def
fetch_attribute
if
left
.
is_a?
(
Arel
::
Attributes
::
Attribute
)
yield
left
elsif
right
.
is_a?
(
Arel
::
Attributes
::
Attribute
)
yield
right
end
end
end
class
IsDistinctFrom
<
Equality
...
...
activerecord/lib/arel/nodes/grouping.rb
浏览文件 @
99b607e6
...
...
@@ -3,6 +3,9 @@
module
Arel
# :nodoc: all
module
Nodes
class
Grouping
<
Unary
def
fetch_attribute
(
&
block
)
expr
.
fetch_attribute
(
&
block
)
end
end
end
end
activerecord/lib/arel/nodes/node.rb
浏览文件 @
99b607e6
...
...
@@ -41,6 +41,9 @@ def to_sql(engine = Table.engine)
collector
=
engine
.
connection
.
visitor
.
accept
self
,
collector
collector
.
value
end
def
fetch_attribute
end
end
end
end
activerecord/lib/arel/nodes/sql_literal.rb
浏览文件 @
99b607e6
...
...
@@ -11,6 +11,9 @@ class SqlLiteral < String
def
encode_with
(
coder
)
coder
.
scalar
=
self
.
to_s
end
def
fetch_attribute
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录