Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
cb67d166
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,发现更多精彩内容 >>
提交
cb67d166
编写于
8月 30, 2010
作者:
J
Jeremy Kemper
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cheaper attribute_method_matchers
上级
4b7b8d9e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
10 addition
and
9 deletion
+10
-9
activemodel/lib/active_model/attribute_methods.rb
activemodel/lib/active_model/attribute_methods.rb
+10
-9
未找到文件。
activemodel/lib/active_model/attribute_methods.rb
浏览文件 @
cb67d166
...
...
@@ -56,6 +56,11 @@ class MissingAttributeError < NoMethodError
module
AttributeMethods
extend
ActiveSupport
::
Concern
included
do
class_attribute
:attribute_method_matchers
,
:instance_writer
=>
false
self
.
attribute_method_matchers
=
[]
end
module
ClassMethods
# Defines an "attribute" method (like +inheritance_column+ or +table_name+).
# A new (class) method will be created with the given name. If a value is
...
...
@@ -143,7 +148,7 @@ def #{name}; #{value.to_s.inspect}; end
# person.clear_name
# person.name # => nil
def
attribute_method_prefix
(
*
prefixes
)
attribute_method_matchers
.
concat
(
prefixes
.
map
{
|
prefix
|
AttributeMethodMatcher
.
new
:prefix
=>
prefix
})
self
.
attribute_method_matchers
+=
prefixes
.
map
{
|
prefix
|
AttributeMethodMatcher
.
new
:prefix
=>
prefix
}
undefine_attribute_methods
end
...
...
@@ -180,7 +185,7 @@ def attribute_method_prefix(*prefixes)
# person.name # => "Bob"
# person.name_short? # => true
def
attribute_method_suffix
(
*
suffixes
)
attribute_method_matchers
.
concat
(
suffixes
.
map
{
|
suffix
|
AttributeMethodMatcher
.
new
:suffix
=>
suffix
})
self
.
attribute_method_matchers
+=
suffixes
.
map
{
|
suffix
|
AttributeMethodMatcher
.
new
:suffix
=>
suffix
}
undefine_attribute_methods
end
...
...
@@ -218,7 +223,7 @@ def attribute_method_suffix(*suffixes)
# person.reset_name_to_default!
# person.name # => 'Gemma'
def
attribute_method_affix
(
*
affixes
)
attribute_method_matchers
.
concat
(
affixes
.
map
{
|
affix
|
AttributeMethodMatcher
.
new
:prefix
=>
affix
[
:prefix
],
:suffix
=>
affix
[
:suffix
]
})
self
.
attribute_method_matchers
+=
affixes
.
map
{
|
affix
|
AttributeMethodMatcher
.
new
:prefix
=>
affix
[
:prefix
],
:suffix
=>
affix
[
:suffix
]
}
undefine_attribute_methods
end
...
...
@@ -338,10 +343,6 @@ def method_missing_target
:"
#{
prefix
}
attribute
#{
suffix
}
"
end
end
def
attribute_method_matchers
#:nodoc:
read_inheritable_attribute
(
:attribute_method_matchers
)
||
write_inheritable_attribute
(
:attribute_method_matchers
,
[])
end
end
# Allows access to the object attributes, which are held in the
...
...
@@ -390,7 +391,7 @@ def attribute_method?(attr_name)
# Returns a struct representing the matching attribute method.
# The struct's attributes are prefix, base and suffix.
def
match_attribute_method?
(
method_name
)
self
.
class
.
send
(
:attribute_method_matchers
)
.
each
do
|
method
|
self
.
class
.
attribute_method_matchers
.
each
do
|
method
|
if
(
match
=
method
.
match
(
method_name
))
&&
attribute_method?
(
match
.
attr_name
)
return
match
end
...
...
@@ -401,7 +402,7 @@ def match_attribute_method?(method_name)
# prevent method_missing from calling private methods with #send
def
guard_private_attribute_method!
(
method_name
,
args
)
if
self
.
class
.
private_method_defined?
(
method_name
)
raise
NoMethodError
.
new
(
"Attempt to call private method"
,
method_name
,
args
)
raise
NoMethodError
.
new
(
"Attempt to call private method
`
#{
method_name
}
'
"
,
method_name
,
args
)
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录