Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
bd920eae
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,发现更多精彩内容 >>
提交
bd920eae
编写于
12月 01, 2011
作者:
J
Jon Leighton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove some unnecessary code etc
上级
e9fb6d04
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
11 addition
and
26 deletion
+11
-26
activerecord/lib/active_record/attribute_methods/read.rb
activerecord/lib/active_record/attribute_methods/read.rb
+8
-7
activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
...b/active_record/attribute_methods/time_zone_conversion.rb
+3
-19
未找到文件。
activerecord/lib/active_record/attribute_methods/read.rb
浏览文件 @
bd920eae
...
...
@@ -49,8 +49,9 @@ def undefine_attribute_methods
# The second, slower, branch is necessary to support instances where the database
# returns columns with extra stuff in (like 'my_column(omg)').
def
define_method_attribute
(
attr_name
)
internal
=
internal_attribute_access_code
(
attr_name
)
external
=
external_attribute_access_code
(
attr_name
)
cast_code
=
attribute_cast_code
(
attr_name
)
internal
=
internal_attribute_access_code
(
attr_name
,
cast_code
)
external
=
external_attribute_access_code
(
attr_name
,
cast_code
)
if
attr_name
=~
ActiveModel
::
AttributeMethods
::
NAME_COMPILABLE_REGEXP
generated_attribute_methods
.
module_eval
<<-
STR
,
__FILE__
,
__LINE__
...
...
@@ -80,10 +81,10 @@ def cacheable_column?(column)
attribute_types_cached_by_default
.
include?
(
column
.
type
)
end
def
internal_attribute_access_code
(
attr_name
)
access_code
=
"(v=@attributes['
#{
attr_name
}
']) &&
#{
attribute_cast_code
(
attr_name
)
}
"
def
internal_attribute_access_code
(
attr_name
,
cast_code
)
access_code
=
"(v=@attributes['
#{
attr_name
}
']) &&
#{
cast_code
}
"
unless
attr_name
==
self
.
primary_key
unless
attr_name
==
primary_key
access_code
.
insert
(
0
,
"missing_attribute('
#{
attr_name
}
', caller) unless @attributes.has_key?('
#{
attr_name
}
'); "
)
end
...
...
@@ -94,8 +95,8 @@ def internal_attribute_access_code(attr_name)
access_code
end
def
external_attribute_access_code
(
attr_name
)
access_code
=
"v &&
#{
attribute_cast_code
(
attr_name
)
}
"
def
external_attribute_access_code
(
attr_name
,
cast_code
)
access_code
=
"v &&
#{
cast_code
}
"
if
cache_attribute?
(
attr_name
)
access_code
=
"attributes_cache[attr_name] ||= (
#{
access_code
}
)"
...
...
activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
浏览文件 @
bd920eae
...
...
@@ -19,27 +19,11 @@ module ClassMethods
# Defined for all +datetime+ and +timestamp+ attributes when +time_zone_aware_attributes+ are enabled.
# This enhanced read method automatically converts the UTC time stored in the database to the time
# zone stored in Time.zone.
def
internal_attribute_access_code
(
attr_name
)
def
internal_attribute_access_code
(
attr_name
,
cast_code
)
column
=
columns_hash
[
attr_name
]
if
create_time_zone_conversion_attribute?
(
attr_name
,
column
)
<<-
CODE
cached = @attributes_cache['
#{
attr_name
}
']
return cached if cached
v = @attributes['
#{
attr_name
}
']
time =
#{
column
.
type_cast_code
(
'v'
)
}
@attributes_cache['
#{
attr_name
}
'] = time.acts_like?(:time) ? time.in_time_zone : time
CODE
else
super
end
end
def
external_attribute_access_code
(
attr_name
)
column
=
columns_hash
[
attr_name
]
if
create_time_zone_conversion_attribute?
(
attr_name
,
column
)
"attributes_cache[attr_name] ||= (
#{
attribute_cast_code
(
attr_name
)
}
)"
super
(
attr_name
,
"(v=
#{
column
.
type_cast_code
(
'v'
)
}
) &&
#{
cast_code
}
"
)
else
super
end
...
...
@@ -47,7 +31,7 @@ def external_attribute_access_code(attr_name)
def
attribute_cast_code
(
attr_name
)
if
create_time_zone_conversion_attribute?
(
attr_name
,
columns_hash
[
attr_name
])
"
v.acts_like?(:time) ? v.in_time_zone : v
"
"
(v.acts_like?(:time) ? v.in_time_zone : v)
"
else
super
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录