Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
3ce6a10b
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,发现更多精彩内容 >>
提交
3ce6a10b
编写于
11月 09, 2009
作者:
J
Jeremy Kemper
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Contortions to work around brittle naming dependency
上级
763489ce
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
30 addition
and
33 deletion
+30
-33
railties/lib/rails/generators/base.rb
railties/lib/rails/generators/base.rb
+25
-27
railties/test/generators_test.rb
railties/test/generators_test.rb
+5
-6
未找到文件。
railties/lib/rails/generators/base.rb
浏览文件 @
3ce6a10b
...
...
@@ -25,8 +25,11 @@ def initialize(*args) #:nodoc:
# Automatically sets the source root based on the class name.
#
def
self
.
source_root
@_rails_source_root
||=
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
base_name
,
generator_name
,
'templates'
))
@_rails_source_root
||=
begin
if
base_name
&&
generator_name
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
base_name
,
generator_name
,
'templates'
))
end
end
end
# Tries to get the description from a USAGE file one folder above the source
...
...
@@ -216,7 +219,7 @@ def self.inherited(base) #:nodoc:
# and can point to wrong directions when inside an specified directory.
base
.
source_root
if
base
.
name
&&
base
.
name
!~
/Base$/
&&
defined?
(
Rails
.
root
)
&&
Rails
.
root
if
base
.
name
&&
base
.
name
!~
/Base$/
&&
base
.
base_name
&&
base
.
generator_name
&&
defined?
(
Rails
.
root
)
&&
Rails
.
root
path
=
File
.
expand_path
(
File
.
join
(
Rails
.
root
,
'lib'
,
'templates'
))
if
base
.
name
.
include?
(
'::'
)
base
.
source_paths
<<
File
.
join
(
path
,
base
.
base_name
,
base
.
generator_name
)
...
...
@@ -276,8 +279,10 @@ def self.banner
# Sets the base_name taking into account the current class namespace.
#
def
self
.
base_name
if
name
@base_name
||=
name
.
split
(
'::'
).
first
.
underscore
@base_name
||=
begin
if
base
=
name
.
to_s
.
split
(
'::'
).
first
base
.
underscore
end
end
end
...
...
@@ -287,46 +292,39 @@ def self.base_name
def
self
.
generator_name
if
name
@generator_name
||=
begin
klass_name
=
name
.
to_s
.
split
(
'::'
).
last
if
klass_name
=
name
.
to_s
.
split
(
'::'
).
last
klass_name
.
sub!
(
/Generator$/
,
''
)
klass_name
.
underscore
end
end
end
end
# Return the default value for the option name given doing a lookup in
# Rails::Generators.options.
#
def
self
.
default_value_for_option
(
name
,
options
)
config
=
Rails
::
Generators
.
options
generator
,
base
=
generator_name
.
to_sym
,
base_name
.
to_sym
if
config
[
generator
]
&&
config
[
generator
].
key?
(
name
)
config
[
generator
][
name
]
elsif
config
[
base
]
&&
config
[
base
].
key?
(
name
)
config
[
base
][
name
]
elsif
config
[
:rails
].
key?
(
name
)
config
[
:rails
][
name
]
else
options
[
:default
]
end
default_for_option
(
Rails
::
Generators
.
options
,
name
,
options
,
options
[
:default
])
end
# Return default aliases for the option name given doing a lookup in
# Rails::Generators.aliases.
#
def
self
.
default_aliases_for_option
(
name
,
options
)
config
=
Rails
::
Generators
.
aliases
generator
,
base
=
generator_name
.
to_sym
,
base_name
.
to_sym
default_for_option
(
Rails
::
Generators
.
aliases
,
name
,
options
,
options
[
:aliases
])
end
if
config
[
generator
]
&&
config
[
generator
].
key?
(
name
)
config
[
generator
][
name
]
elsif
config
[
base
]
&&
config
[
base
].
key?
(
name
)
config
[
base
][
name
]
# Return default for the option name given doing a lookup in config.
#
def
self
.
default_for_option
(
config
,
name
,
options
,
default
)
if
generator_name
and
c
=
config
[
generator_name
.
to_sym
]
and
c
.
key?
(
name
)
c
[
name
]
elsif
base_name
and
c
=
config
[
base_name
.
to_sym
]
and
c
.
key?
(
name
)
c
[
name
]
elsif
config
[
:rails
].
key?
(
name
)
config
[
:rails
][
name
]
else
options
[
:aliases
]
default
end
end
...
...
railties/test/generators_test.rb
浏览文件 @
3ce6a10b
...
...
@@ -165,13 +165,12 @@ def test_nested_fallbacks_for_generators
def
test_developer_options_are_overwriten_by_user_options
Rails
::
Generators
.
options
[
:new_generator
]
=
{
:generate
=>
false
}
self
.
class
.
class_eval
<<-
end_eval
class NewGenerator < Rails::Generators::Base
klass
=
Class
.
new
(
Rails
::
Generators
::
Base
)
do
def
self
.
name
()
'NewGenerator'
end
class_option
:generate
,
:default
=>
true
end
end_eval
assert_equal
false
,
NewGenerator
.
class_options
[
:generate
].
default
assert_equal
false
,
klass
.
class_options
[
:generate
].
default
end
def
test_source_paths_for_not_namespaced_generators
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录