Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
d5d0b8ea
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,发现更多精彩内容 >>
提交
d5d0b8ea
编写于
6月 30, 2009
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Removing unecessary class methods.
上级
35c4df4a
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
34 addition
and
47 deletion
+34
-47
railties/lib/generators/active_record/model/model_generator.rb
...ies/lib/generators/active_record/model/model_generator.rb
+3
-4
railties/lib/generators/base.rb
railties/lib/generators/base.rb
+21
-33
railties/lib/generators/rails/controller/controller_generator.rb
...s/lib/generators/rails/controller/controller_generator.rb
+1
-1
railties/lib/generators/rails/resource/resource_generator.rb
railties/lib/generators/rails/resource/resource_generator.rb
+5
-8
railties/lib/generators/rails/scaffold/scaffold_generator.rb
railties/lib/generators/rails/scaffold/scaffold_generator.rb
+2
-0
railties/lib/generators/rails/scaffold_controller/scaffold_controller_generator.rb
...ails/scaffold_controller/scaffold_controller_generator.rb
+1
-0
railties/lib/generators/test_unit/model/model_generator.rb
railties/lib/generators/test_unit/model/model_generator.rb
+1
-1
未找到文件。
railties/lib/generators/active_record/model/model_generator.rb
浏览文件 @
d5d0b8ea
...
...
@@ -7,10 +7,9 @@ class ModelGenerator < Base
check_class_collision
conditional_class_options
:migration
,
:timestamps
class_option
:parent
,
:type
=>
:string
,
:desc
=>
"The parent class for the generated model"
class_option
:migration
,
:type
=>
:boolean
class_option
:timestamps
,
:type
=>
:boolean
class_option
:parent
,
:type
=>
:string
,
:desc
=>
"The parent class for the generated model"
def
create_model_file
template
'model.rb'
,
File
.
join
(
'app/models'
,
class_path
,
"
#{
file_name
}
.rb"
)
...
...
railties/lib/generators/base.rb
浏览文件 @
d5d0b8ea
...
...
@@ -3,18 +3,22 @@
module
Rails
module
Generators
DEFAULTS
=
{
:actions
=>
[],
:fixture
=>
true
,
:force_plural
=>
false
,
:helper
=>
true
,
:migration
=>
true
,
:orm
=>
'active_record'
,
:resource_controller
=>
'controller'
,
:scaffold_controller
=>
'scaffold_controller'
,
:singleton
=>
false
,
:test_framework
=>
'test_unit'
,
:template_engine
=>
'erb'
,
:timestamps
=>
true
}
ALIASES
=
{
:actions
=>
'-a'
,
:fixture_replacement
=>
'-r'
,
:orm
=>
'-o'
,
:resource_controller
=>
'-c'
,
...
...
@@ -109,12 +113,14 @@ def self.namespace(name=nil)
# end
#
def
self
.
hook_for
(
*
names
,
&
block
)
default_class_options
(
*
names
)
options
=
names
.
extract_options!
as
=
options
.
fetch
(
:as
,
generator_name
)
verbose
=
options
.
fetch
(
:verbose
,
:blue
)
names
.
each
do
|
name
|
default
=
{
:desc
=>
"
#{
name
.
to_s
.
humanize
}
to be invoked"
,
:banner
=>
"NAME"
}
class_option
name
,
default
.
merge!
(
options
)
invocations
<<
[
name
,
base_name
,
as
]
invocation_blocks
[
name
]
=
block
if
block_given?
...
...
@@ -165,12 +171,13 @@ def invoke_for_#{name}
# for usage and examples.
#
def
self
.
invoke_if
(
*
names
,
&
block
)
conditional_class_options
(
*
names
)
options
=
names
.
extract_options!
options
=
names
.
extract_options!
.
merge
(
:type
=>
:boolean
)
as
=
options
.
fetch
(
:as
,
generator_name
)
verbose
=
options
.
fetch
(
:verbose
,
:blue
)
names
.
each
do
|
name
|
class_option
name
,
options
invocations
<<
[
name
,
base_name
,
as
]
invocation_blocks
[
name
]
=
block
if
block_given?
...
...
@@ -207,6 +214,15 @@ def self.remove_hook_for(*names)
end
end
# Make class option aware of DEFAULTS and ALIASES.
#
def
self
.
class_option
(
name
,
options
)
#:nodoc:
options
[
:desc
]
=
"Indicates when to generate
#{
name
.
to_s
.
humanize
.
downcase
}
"
unless
options
.
key?
(
:desc
)
options
[
:aliases
]
=
ALIASES
[
name
]
unless
options
.
key?
(
:aliases
)
options
[
:default
]
=
DEFAULTS
[
name
]
unless
options
.
key?
(
:default
)
super
(
name
,
options
)
end
protected
# This is the common method that both hook_for and invoke_if use to
...
...
@@ -288,34 +304,6 @@ def self.invocation_blocks #:nodoc:
@invocation_blocks
||=
from_superclass
(
:invocation_blocks
,
{})
end
# Creates a conditional class option with type boolean, default value
# lookup and default description.
#
def
self
.
conditional_class_options
(
*
names
)
default_options
=
names
.
extract_options!
names
.
each
do
|
name
|
options
=
default_options
.
dup
options
[
:desc
]
||=
"Indicates when to generate
#{
name
.
to_s
.
humanize
.
downcase
}
"
class_option
name
,
options
.
merge!
(
:type
=>
:boolean
,
:default
=>
DEFAULTS
[
name
]
||
false
)
end
end
# Creates a class option with type default, banner, alias lookup and
# description. Used internally by hook_for (ie, not part of plugin API).
#
def
self
.
default_class_options
(
*
names
)
#:nodoc:
default_options
=
names
.
extract_options!
names
.
each
do
|
name
|
options
=
default_options
.
dup
options
[
:desc
]
||=
"
#{
name
.
to_s
.
humanize
}
to be invoked"
options
[
:banner
]
||=
"NAME"
options
[
:aliases
]
||=
ALIASES
[
name
]
class_option
name
,
options
.
merge!
(
:type
=>
:default
,
:default
=>
DEFAULTS
[
name
])
end
end
# Overwrite class options help to allow invoked generators options to be
# shown when invoking a generator. Only first and second level options
# are shown, for instance, if a generator invokes an ORM that invokes
...
...
@@ -338,7 +326,7 @@ def self.class_options_help(shell, ungrouped_name=nil, extra_group=nil)
# in base_options are not added twice.
#
def
self
.
get_options_from_invocations
(
group_options
,
base_options
)
invocations
.
sort
{
|
a
,
b
|
a
[
0
].
to_s
<=>
b
[
0
].
to_s
}.
each
do
|
args
|
invocations
.
each
do
|
args
|
name
,
base
,
generator
=
args
option
=
class_options
[
name
]
...
...
@@ -353,7 +341,7 @@ def self.get_options_from_invocations(group_options, base_options)
group_options
[
human_name
]
+=
klass
.
class_options
.
values
.
select
do
|
option
|
base_options
[
option
.
name
.
to_sym
].
nil?
&&
option
.
group
.
nil?
&&
!
group_options
[
human_name
]
.
any?
{
|
i
|
i
.
name
==
option
.
name
}
!
group_options
.
values
.
flatten
.
any?
{
|
i
|
i
.
name
==
option
.
name
}
end
yield
klass
if
block_given?
...
...
railties/lib/generators/rails/controller/controller_generator.rb
浏览文件 @
d5d0b8ea
module
Rails
module
Generators
class
ControllerGenerator
<
NamedBase
argument
:actions
,
:type
=>
:array
,
:default
=>
[
],
:banner
=>
"action action"
argument
:actions
,
:type
=>
:array
,
:default
=>
DEFAULTS
[
:actions
],
:banner
=>
"action action"
check_class_collision
:suffix
=>
"Controller"
def
create_controller_files
...
...
railties/lib/generators/rails/resource/resource_generator.rb
浏览文件 @
d5d0b8ea
...
...
@@ -2,19 +2,16 @@
module
Rails
module
Generators
class
ResourceGenerator
<
ModelGenerator
class
ResourceGenerator
<
ModelGenerator
#metagenerator
hook_for
:resource_controller
do
|
base
,
controller
|
base
.
invoke
controller
,
[
base
.
name
.
pluralize
,
base
.
options
[
:actions
]
]
end
class_option
:actions
,
:type
=>
:array
,
:
default
=>
[],
:
banner
=>
"ACTION ACTION"
,
:desc
=>
"Actions for the resource controller"
,
:aliases
=>
"-a"
class_option
:actions
,
:type
=>
:array
,
:banner
=>
"ACTION ACTION"
,
:desc
=>
"Actions for the resource controller"
class_option
:singleton
,
:type
=>
:boolean
,
:default
=>
false
,
:aliases
=>
"-i"
,
:desc
=>
"Supply to create a singleton controller"
class_option
:force_plural
,
:type
=>
:boolean
,
:default
=>
false
,
:aliases
=>
"-u"
,
:desc
=>
"Forces the use of a plural ModelName"
class_option
:singleton
,
:type
=>
:boolean
,
:desc
=>
"Supply to create a singleton controller"
class_option
:force_plural
,
:type
=>
:boolean
,
:desc
=>
"Forces the use of a plural ModelName"
def
initialize
(
args
=
[],
options
=
{},
config
=
{})
super
...
...
railties/lib/generators/rails/scaffold/scaffold_generator.rb
浏览文件 @
d5d0b8ea
...
...
@@ -3,6 +3,8 @@
module
Rails
module
Generators
class
ScaffoldGenerator
<
ResourceGenerator
#metagenerator
class_option
:test_framework
,
:banner
=>
"NAME"
,
:desc
=>
"Test framework to be invoked"
remove_hook_for
:actions
,
:resource_controller
hook_for
:scaffold_controller
end
...
...
railties/lib/generators/rails/scaffold_controller/scaffold_controller_generator.rb
浏览文件 @
d5d0b8ea
module
Rails
module
Generators
class
ScaffoldControllerGenerator
<
NamedBase
class_option
:singleton
,
:type
=>
:boolean
,
:desc
=>
"Supply to create a singleton controller"
check_class_collision
:suffix
=>
"Controller"
def
create_controller_files
...
...
railties/lib/generators/test_unit/model/model_generator.rb
浏览文件 @
d5d0b8ea
...
...
@@ -4,9 +4,9 @@ module TestUnit
module
Generators
class
ModelGenerator
<
Base
argument
:attributes
,
:type
=>
:hash
,
:default
=>
{},
:banner
=>
"field:type field:type"
class_option
:fixture
,
:type
=>
:boolean
check_class_collision
:suffix
=>
"Test"
conditional_class_options
:fixture
def
create_test_file
template
'unit_test.rb'
,
File
.
join
(
'test/unit'
,
class_path
,
"
#{
file_name
}
_test.rb"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录