Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
218105f5
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,发现更多精彩内容 >>
提交
218105f5
编写于
6月 16, 2014
作者:
S
Sean Griffin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor in-place dirty checking to use the attribute object
上级
d8569bd4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
26 addition
and
9 deletion
+26
-9
activerecord/lib/active_record/attribute.rb
activerecord/lib/active_record/attribute.rb
+19
-0
activerecord/lib/active_record/attribute_methods/dirty.rb
activerecord/lib/active_record/attribute_methods/dirty.rb
+3
-9
activerecord/lib/active_record/attribute_methods/read.rb
activerecord/lib/active_record/attribute_methods/read.rb
+4
-0
未找到文件。
activerecord/lib/active_record/attribute.rb
浏览文件 @
218105f5
...
...
@@ -29,6 +29,14 @@ def value_for_database
type
.
type_cast_for_database
(
value
)
end
def
changed_from?
(
old_value
)
type
.
changed?
(
old_value
,
value
,
value_before_type_cast
)
end
def
changed_in_place_from?
(
old_value
)
type
.
changed_in_place?
(
old_value
,
value
)
end
def
type_cast
raise
NotImplementedError
end
...
...
@@ -52,5 +60,16 @@ def type_cast(value)
type
.
type_cast_from_user
(
value
)
end
end
class
Null
class
<<
self
attr_reader
:value
,
:value_before_type_cast
,
:value_for_database
def
changed_from?
(
*
)
false
end
alias
changed_in_place_from?
changed_from?
end
end
end
end
activerecord/lib/active_record/attribute_methods/dirty.rb
浏览文件 @
218105f5
...
...
@@ -137,9 +137,7 @@ def keys_for_partial_write
end
def
_field_changed?
(
attr
,
old_value
)
new_value
=
read_attribute
(
attr
)
raw_value
=
read_attribute_before_type_cast
(
attr
)
column_for_attribute
(
attr
).
changed?
(
old_value
,
new_value
,
raw_value
)
attribute_named
(
attr
).
changed_from?
(
old_value
)
end
def
changed_in_place
...
...
@@ -149,10 +147,8 @@ def changed_in_place
end
def
changed_in_place?
(
attr_name
)
type
=
type_for_attribute
(
attr_name
)
old_value
=
original_raw_attribute
(
attr_name
)
value
=
read_attribute
(
attr_name
)
type
.
changed_in_place?
(
old_value
,
value
)
attribute_named
(
attr_name
).
changed_in_place_from?
(
old_value
)
end
def
original_raw_attribute
(
attr_name
)
...
...
@@ -166,9 +162,7 @@ def original_raw_attributes
end
def
store_original_raw_attribute
(
attr_name
)
type
=
type_for_attribute
(
attr_name
)
value
=
type
.
type_cast_for_database
(
read_attribute
(
attr_name
))
original_raw_attributes
[
attr_name
]
=
value
original_raw_attributes
[
attr_name
]
=
attribute_named
(
attr_name
).
value_for_database
end
def
store_original_raw_attributes
...
...
activerecord/lib/active_record/attribute_methods/read.rb
浏览文件 @
218105f5
...
...
@@ -99,6 +99,10 @@ def read_attribute(attr_name)
def
attribute
(
attribute_name
)
read_attribute
(
attribute_name
)
end
def
attribute_named
(
attribute_name
)
@attributes
.
fetch
(
attribute_name
,
Attribute
::
Null
)
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录