Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
a6cf6ec9
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,发现更多精彩内容 >>
提交
a6cf6ec9
编写于
2月 01, 2011
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move the coders to the serialized_attributes hash
上级
69600a9f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
17 addition
and
18 deletion
+17
-18
activerecord/lib/active_record/attribute_methods/read.rb
activerecord/lib/active_record/attribute_methods/read.rb
+3
-7
activerecord/lib/active_record/base.rb
activerecord/lib/active_record/base.rb
+4
-8
activerecord/lib/active_record/coders/yaml_column.rb
activerecord/lib/active_record/coders/yaml_column.rb
+6
-1
activerecord/lib/active_record/validations/uniqueness.rb
activerecord/lib/active_record/validations/uniqueness.rb
+4
-2
未找到文件。
activerecord/lib/active_record/attribute_methods/read.rb
浏览文件 @
a6cf6ec9
...
...
@@ -106,14 +106,10 @@ def unserializable_attribute?(attr_name, column)
# Returns the unserialized object of the attribute.
def
unserialize_attribute
(
attr_name
)
unserialized_object
=
object_from_yaml
(
@attributes
[
attr_name
])
coder
=
self
.
class
.
serialized_attributes
[
attr_name
]
unserialized_object
=
coder
.
load
(
@attributes
[
attr_name
])
if
unserialized_object
.
is_a?
(
self
.
class
.
serialized_attributes
[
attr_name
])
||
unserialized_object
.
nil?
@attributes
.
frozen?
?
unserialized_object
:
@attributes
[
attr_name
]
=
unserialized_object
else
raise
SerializationTypeMismatch
,
"
#{
attr_name
}
was supposed to be a
#{
self
.
class
.
serialized_attributes
[
attr_name
]
}
, but was a
#{
unserialized_object
.
class
.
to_s
}
"
end
@attributes
.
frozen?
?
unserialized_object
:
@attributes
[
attr_name
]
=
unserialized_object
end
private
...
...
activerecord/lib/active_record/base.rb
浏览文件 @
a6cf6ec9
...
...
@@ -536,7 +536,7 @@ def readonly_attributes
# serialize :preferences
# end
def
serialize
(
attr_name
,
class_name
=
Object
)
serialized_attributes
[
attr_name
.
to_s
]
=
class_name
serialized_attributes
[
attr_name
.
to_s
]
=
Coders
::
YAMLColumn
.
new
(
class_name
)
end
# Guesses the table name (in forced lower-case) based on the name of the class in the
...
...
@@ -1738,8 +1738,9 @@ def arel_attributes_values(include_primary_key = true, include_readonly_attribut
if
include_readonly_attributes
||
(
!
include_readonly_attributes
&&
!
self
.
class
.
readonly_attributes
.
include?
(
name
))
value
=
read_attribute
(
name
)
if
!
value
.
nil?
&&
self
.
class
.
serialized_attributes
.
key?
(
name
)
value
=
YAML
.
dump
value
coder
=
self
.
class
.
serialized_attributes
[
name
]
if
!
value
.
nil?
&&
coder
value
=
coder
.
dump
value
end
attrs
[
self
.
class
.
arel_table
[
name
]]
=
value
end
...
...
@@ -1865,11 +1866,6 @@ def convert_number_column_value(value)
end
end
def
object_from_yaml
(
string
)
return
string
unless
string
.
is_a?
(
String
)
&&
string
=~
/^---/
YAML
::
load
(
string
)
rescue
string
end
def
populate_with_current_scope_attributes
if
scope
=
self
.
class
.
send
(
:current_scoped_methods
)
create_with
=
scope
.
scope_for_create
...
...
activerecord/lib/active_record/coders/yaml_column.rb
浏览文件 @
a6cf6ec9
...
...
@@ -14,16 +14,21 @@ def initialize(object_class = Object)
@object_class
=
object_class
end
def
dump
(
obj
)
YAML
.
dump
obj
end
def
load
(
yaml
)
return
yaml
unless
yaml
.
is_a?
(
String
)
&&
yaml
=~
/^---/
begin
obj
=
YAML
::
load
(
yaml
)
obj
=
YAML
.
load
(
yaml
)
unless
obj
.
is_a?
(
object_class
)
||
obj
.
nil?
raise
SerializationTypeMismatch
,
"Attribute was supposed to be a
#{
object_class
}
, but was a
#{
obj
.
class
}
"
end
obj
rescue
*
RESCUE_ERRORS
yaml
end
...
...
activerecord/lib/active_record/validations/uniqueness.rb
浏览文件 @
a6cf6ec9
...
...
@@ -15,8 +15,10 @@ def setup(klass)
def
validate_each
(
record
,
attribute
,
value
)
finder_class
=
find_finder_class_for
(
record
)
if
value
&&
record
.
class
.
serialized_attributes
.
key?
(
attribute
.
to_s
)
value
=
YAML
.
dump
value
coder
=
record
.
class
.
serialized_attributes
[
attribute
.
to_s
]
if
value
&&
coder
value
=
coder
.
dump
value
end
sql
,
params
=
mount_sql_and_params
(
finder_class
,
record
.
class
.
quoted_table_name
,
attribute
,
value
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录