Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
ae44bf7c
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,发现更多精彩内容 >>
提交
ae44bf7c
编写于
11月 18, 2010
作者:
J
Josh Kalderimis
提交者:
José Valim
11月 18, 2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
bye bye extlib_inheritable_*, AS callbacks now using class_attribute
Signed-off-by:
N
José Valim
<
jose.valim@gmail.com
>
上级
43e2e10f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
13 addition
and
92 deletion
+13
-92
activesupport/lib/active_support/callbacks.rb
activesupport/lib/active_support/callbacks.rb
+13
-9
activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb
...b/active_support/core_ext/class/inheritable_attributes.rb
+0
-83
未找到文件。
activesupport/lib/active_support/callbacks.rb
浏览文件 @
ae44bf7c
require
'active_support/descendants_tracker'
require
'active_support/core_ext/array/wrap'
require
'active_support/core_ext/class/
inheritable_attributes
'
require
'active_support/core_ext/class/
attribute
'
require
'active_support/core_ext/kernel/reporting'
require
'active_support/core_ext/kernel/singleton_class'
...
...
@@ -437,7 +437,7 @@ def __update_callbacks(name, filters = [], block = nil) #:nodoc:
([
self
]
+
ActiveSupport
::
DescendantsTracker
.
descendants
(
self
)).
each
do
|
target
|
chain
=
target
.
send
(
"_
#{
name
}
_callbacks"
)
yield
chain
,
type
,
filters
,
options
yield
target
,
chain
.
dup
,
type
,
filters
,
options
target
.
__define_runner
(
name
)
end
end
...
...
@@ -473,7 +473,7 @@ def __update_callbacks(name, filters = [], block = nil) #:nodoc:
def
set_callback
(
name
,
*
filter_list
,
&
block
)
mapped
=
nil
__update_callbacks
(
name
,
filter_list
,
block
)
do
|
chain
,
type
,
filters
,
options
|
__update_callbacks
(
name
,
filter_list
,
block
)
do
|
target
,
chain
,
type
,
filters
,
options
|
mapped
||=
filters
.
map
do
|
filter
|
Callback
.
new
(
chain
,
filter
,
type
,
options
.
dup
,
self
)
end
...
...
@@ -483,6 +483,8 @@ def set_callback(name, *filter_list, &block)
end
options
[
:prepend
]
?
chain
.
unshift
(
*
(
mapped
.
reverse
))
:
chain
.
push
(
*
mapped
)
target
.
send
(
"_
#{
name
}
_callbacks="
,
chain
)
end
end
...
...
@@ -493,7 +495,7 @@ def set_callback(name, *filter_list, &block)
# end
#
def
skip_callback
(
name
,
*
filter_list
,
&
block
)
__update_callbacks
(
name
,
filter_list
,
block
)
do
|
chain
,
type
,
filters
,
options
|
__update_callbacks
(
name
,
filter_list
,
block
)
do
|
target
,
chain
,
type
,
filters
,
options
|
filters
.
each
do
|
filter
|
filter
=
chain
.
find
{
|
c
|
c
.
matches?
(
type
,
filter
)
}
...
...
@@ -505,6 +507,7 @@ def skip_callback(name, *filter_list, &block)
chain
.
delete
(
filter
)
end
target
.
send
(
"_
#{
name
}
_callbacks="
,
chain
)
end
end
...
...
@@ -514,12 +517,14 @@ def reset_callbacks(symbol)
callbacks
=
send
(
"_
#{
symbol
}
_callbacks"
)
ActiveSupport
::
DescendantsTracker
.
descendants
(
self
).
each
do
|
target
|
chain
=
target
.
send
(
"_
#{
symbol
}
_callbacks"
)
chain
=
target
.
send
(
"_
#{
symbol
}
_callbacks"
)
.
dup
callbacks
.
each
{
|
c
|
chain
.
delete
(
c
)
}
target
.
send
(
"_
#{
symbol
}
_callbacks="
,
chain
)
target
.
__define_runner
(
symbol
)
end
callbacks
.
clear
self
.
send
(
"_
#{
symbol
}
_callbacks="
,
callbacks
.
dup
.
clear
)
__define_runner
(
symbol
)
end
...
...
@@ -589,9 +594,8 @@ def reset_callbacks(symbol)
def
define_callbacks
(
*
callbacks
)
config
=
callbacks
.
last
.
is_a?
(
Hash
)
?
callbacks
.
pop
:
{}
callbacks
.
each
do
|
callback
|
extlib_inheritable_reader
(
"_
#{
callback
}
_callbacks"
)
do
CallbackChain
.
new
(
callback
,
config
)
end
class_attribute
"_
#{
callback
}
_callbacks"
send
(
"_
#{
callback
}
_callbacks="
,
CallbackChain
.
new
(
callback
,
config
))
__define_runner
(
callback
)
end
end
...
...
activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb
浏览文件 @
ae44bf7c
...
...
@@ -169,86 +169,3 @@ def inherited_with_inheritable_attributes(child)
alias
inherited_without_inheritable_attributes
inherited
alias
inherited
inherited_with_inheritable_attributes
end
class
Class
# Defines class-level inheritable attribute reader. Attributes are available to subclasses,
# each subclass has a copy of parent's attribute.
#
# @param *syms<Array[#to_s]> Array of attributes to define inheritable reader for.
# @return <Array[#to_s]> Array of attributes converted into inheritable_readers.
#
# @api public
#
# @todo Do we want to block instance_reader via :instance_reader => false
# @todo It would be preferable that we do something with a Hash passed in
# (error out or do the same as other methods above) instead of silently
# moving on). In particular, this makes the return value of this function
# less useful.
def
extlib_inheritable_reader
(
*
ivars
,
&
block
)
options
=
ivars
.
extract_options!
ivars
.
each
do
|
ivar
|
self
.
class_eval
<<-
RUBY
,
__FILE__
,
__LINE__
+
1
def self.
#{
ivar
}
return @
#{
ivar
}
if self.object_id ==
#{
self
.
object_id
}
|| defined?(@
#{
ivar
}
)
ivar = superclass.
#{
ivar
}
return nil if ivar.nil? && !
#{
self
}
.instance_variable_defined?("@
#{
ivar
}
")
@
#{
ivar
}
= ivar.duplicable? ? ivar.dup : ivar
end
RUBY
unless
options
[
:instance_reader
]
==
false
self
.
class_eval
<<-
RUBY
,
__FILE__
,
__LINE__
+
1
def
#{
ivar
}
self.class.
#{
ivar
}
end
RUBY
end
instance_variable_set
(
:"@
#{
ivar
}
"
,
yield
)
if
block_given?
end
end
# Defines class-level inheritable attribute writer. Attributes are available to subclasses,
# each subclass has a copy of parent's attribute.
#
# @param *syms<Array[*#to_s, Hash{:instance_writer => Boolean}]> Array of attributes to
# define inheritable writer for.
# @option syms :instance_writer<Boolean> if true, instance-level inheritable attribute writer is defined.
# @return <Array[#to_s]> An Array of the attributes that were made into inheritable writers.
#
# @api public
#
# @todo We need a style for class_eval <<-HEREDOC. I'd like to make it
# class_eval(<<-RUBY, __FILE__, __LINE__), but we should codify it somewhere.
def
extlib_inheritable_writer
(
*
ivars
)
options
=
ivars
.
extract_options!
ivars
.
each
do
|
ivar
|
self
.
class_eval
<<-
RUBY
,
__FILE__
,
__LINE__
+
1
def self.
#{
ivar
}
=(obj)
@
#{
ivar
}
= obj
end
RUBY
unless
options
[
:instance_writer
]
==
false
self
.
class_eval
<<-
RUBY
,
__FILE__
,
__LINE__
+
1
def
#{
ivar
}
=(obj) self.class.
#{
ivar
}
= obj end
RUBY
end
self
.
send
(
"
#{
ivar
}
="
,
yield
)
if
block_given?
end
end
# Defines class-level inheritable attribute accessor. Attributes are available to subclasses,
# each subclass has a copy of parent's attribute.
#
# @param *syms<Array[*#to_s, Hash{:instance_writer => Boolean}]> Array of attributes to
# define inheritable accessor for.
# @option syms :instance_writer<Boolean> if true, instance-level inheritable attribute writer is defined.
# @return <Array[#to_s]> An Array of attributes turned into inheritable accessors.
#
# @api public
def
extlib_inheritable_accessor
(
*
syms
,
&
block
)
extlib_inheritable_reader
(
*
syms
)
extlib_inheritable_writer
(
*
syms
,
&
block
)
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录