Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
94384bdb
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,发现更多精彩内容 >>
提交
94384bdb
编写于
1月 15, 2013
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #8955 from burns/source_annotation
Allow a `:dirs` option to `SourceAnnotationExtractor.enumerate`
上级
e42b5f99
5a9b3b7a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
76 addition
and
16 deletion
+76
-16
railties/CHANGELOG.md
railties/CHANGELOG.md
+6
-0
railties/lib/rails/source_annotation_extractor.rb
railties/lib/rails/source_annotation_extractor.rb
+31
-16
railties/test/application/rake/notes_test.rb
railties/test/application/rake/notes_test.rb
+39
-0
未找到文件。
railties/CHANGELOG.md
浏览文件 @
94384bdb
## Rails 4.0.0 (unreleased) ##
## Rails 4.0.0 (unreleased) ##
*
Allow a
`:dirs`
key in the
`SourceAnnotationExtractor.enumerate`
options
to explicitly set the directories to be traversed so it's easier to define
custom rake tasks.
*Brian D. Burns*
*
Deprecate
`Rails::Generators::ActiveModel#update_attributes`
in favor of
`#update`
.
*
Deprecate
`Rails::Generators::ActiveModel#update_attributes`
in favor of
`#update`
.
ORMs that implement `Generators::ActiveModel#update_attributes` should change
ORMs that implement `Generators::ActiveModel#update_attributes` should change
...
...
railties/lib/rails/source_annotation_extractor.rb
浏览文件 @
94384bdb
...
@@ -32,15 +32,24 @@ def to_s(options={})
...
@@ -32,15 +32,24 @@ def to_s(options={})
end
end
# Prints all annotations with tag +tag+ under the root directories +app+,
# Prints all annotations with tag +tag+ under the root directories +app+,
# +config+, +lib+, and +test+ (recursively). Filenames with extension
# +config+, +db+, +lib+, and +test+ (recursively).
# +.builder+, +.rb+, +.erb+, +.haml+, +.slim+, +.css+, +.scss+, +.js+,
#
# +.coffee+, and +.rake+ are taken into account. The +options+ hash is
# Additional directories may be added using a comma-delimited list set using
# passed to each annotation's +to_s+.
# <tt>ENV['SOURCE_ANNOTATION_DIRECTORIES']</tt>.
#
# Directories may also be explicitly set using the <tt>:dirs</tt> key in +options+.
#
# SourceAnnotationExtractor.enumerate 'TODO|FIXME', dirs: %w(app lib), tag: true
#
# If +options+ has a <tt>:tag</tt> flag, it will be passed to each annotation's +to_s+.
#
# See <tt>#find_in</tt> for a list of file extensions that will be taken into account.
#
#
# This class method is the single entry point for the rake tasks.
# This class method is the single entry point for the rake tasks.
def
self
.
enumerate
(
tag
,
options
=
{})
def
self
.
enumerate
(
tag
,
options
=
{})
extractor
=
new
(
tag
)
extractor
=
new
(
tag
)
extractor
.
display
(
extractor
.
find
,
options
)
dirs
=
options
.
delete
(
:dirs
)
||
Annotation
.
directories
extractor
.
display
(
extractor
.
find
(
dirs
),
options
)
end
end
attr_reader
:tag
attr_reader
:tag
...
@@ -51,7 +60,7 @@ def initialize(tag)
...
@@ -51,7 +60,7 @@ def initialize(tag)
# Returns a hash that maps filenames under +dirs+ (recursively) to arrays
# Returns a hash that maps filenames under +dirs+ (recursively) to arrays
# with their annotations.
# with their annotations.
def
find
(
dirs
=
Annotation
.
directories
)
def
find
(
dirs
)
dirs
.
inject
({})
{
|
h
,
dir
|
h
.
update
(
find_in
(
dir
))
}
dirs
.
inject
({})
{
|
h
,
dir
|
h
.
update
(
find_in
(
dir
))
}
end
end
...
@@ -68,16 +77,22 @@ def find_in(dir)
...
@@ -68,16 +77,22 @@ def find_in(dir)
if
File
.
directory?
(
item
)
if
File
.
directory?
(
item
)
results
.
update
(
find_in
(
item
))
results
.
update
(
find_in
(
item
))
elsif
item
=~
/\.(builder|rb|coffee|rake)$/
else
results
.
update
(
extract_annotations_from
(
item
,
/#\s*(
#{
tag
}
):?\s*(.*)$/
))
pattern
=
elsif
item
=~
/\.(css|scss|js)$/
case
item
results
.
update
(
extract_annotations_from
(
item
,
/\/\/\s*(
#{
tag
}
):?\s*(.*)$/
))
when
/\.(builder|rb|coffee|rake)$/
elsif
item
=~
/\.erb$/
/#\s*(
#{
tag
}
):?\s*(.*)$/
results
.
update
(
extract_annotations_from
(
item
,
/<%\s*#\s*(
#{
tag
}
):?\s*(.*?)\s*%>/
))
when
/\.(css|scss|js)$/
elsif
item
=~
/\.haml$/
/\/\/\s*(
#{
tag
}
):?\s*(.*)$/
results
.
update
(
extract_annotations_from
(
item
,
/-\s*#\s*(
#{
tag
}
):?\s*(.*)$/
))
when
/\.erb$/
elsif
item
=~
/\.slim$/
/<%\s*#\s*(
#{
tag
}
):?\s*(.*?)\s*%>/
results
.
update
(
extract_annotations_from
(
item
,
/\/\s*\s*(
#{
tag
}
):?\s*(.*)$/
))
when
/\.haml$/
/-\s*#\s*(
#{
tag
}
):?\s*(.*)$/
when
/\.slim$/
/\/\s*\s*(
#{
tag
}
):?\s*(.*)$/
else
nil
end
results
.
update
(
extract_annotations_from
(
item
,
pattern
))
if
pattern
end
end
end
end
...
...
railties/test/application/rake/notes_test.rb
浏览文件 @
94384bdb
...
@@ -130,6 +130,45 @@ def teardown
...
@@ -130,6 +130,45 @@ def teardown
end
end
end
end
test
'custom rake task finds specific notes in specific directories'
do
app_file
"app/controllers/some_controller.rb"
,
"# TODO: note in app directory"
app_file
"lib/some_file.rb"
,
"# OPTIMIZE: note in lib directory
\n
"
<<
"# FIXME: note in lib directory"
app_file
"test/some_test.rb"
,
1000
.
times
.
map
{
""
}.
join
(
"
\n
"
)
<<
"# TODO: note in test directory"
app_file
"lib/tasks/notes_custom.rake"
,
<<-
EOS
require 'rails/source_annotation_extractor'
task :notes_custom do
tags = 'TODO|FIXME'
opts = { dirs: %w(lib test), tag: true }
SourceAnnotationExtractor.enumerate(tags, opts)
end
EOS
boot_rails
require
'rake'
require
'rdoc/task'
require
'rake/testtask'
Rails
.
application
.
load_tasks
Dir
.
chdir
(
app_path
)
do
output
=
`bundle exec rake notes_custom`
lines
=
output
.
scan
(
/\[([0-9\s]+)\]/
).
flatten
assert_match
(
/\[FIXME\] note in lib directory/
,
output
)
assert_match
(
/\[TODO\] note in test directory/
,
output
)
assert_no_match
(
/OPTIMIZE/
,
output
)
assert_no_match
(
/note in app directory/
,
output
)
assert_equal
2
,
lines
.
size
lines
.
each
do
|
line_number
|
assert_equal
4
,
line_number
.
size
end
end
end
private
private
def
boot_rails
def
boot_rails
super
super
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录