erails 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +3 -0
- data/MIT-LICENSE +20 -0
- data/README +309 -0
- data/Rakefile +339 -0
- data/bin/about +4 -0
- data/bin/console +3 -0
- data/bin/dbconsole +3 -0
- data/bin/destroy +3 -0
- data/bin/erails +19 -0
- data/bin/generate +3 -0
- data/bin/performance/benchmarker +3 -0
- data/bin/performance/profiler +3 -0
- data/bin/performance/request +3 -0
- data/bin/plugin +3 -0
- data/bin/process/inspector +3 -0
- data/bin/process/reaper +3 -0
- data/bin/process/spawner +3 -0
- data/bin/runner +3 -0
- data/bin/server +3 -0
- data/builtin/rails_info/rails/info.rb +125 -0
- data/builtin/rails_info/rails/info_controller.rb +9 -0
- data/builtin/rails_info/rails/info_helper.rb +2 -0
- data/builtin/rails_info/rails_info_controller.rb +2 -0
- data/configs/apache.conf +40 -0
- data/configs/databases/frontbase.yml +28 -0
- data/configs/databases/mysql.yml +54 -0
- data/configs/databases/oracle.yml +39 -0
- data/configs/databases/postgresql.yml +48 -0
- data/configs/databases/sqlite2.yml +16 -0
- data/configs/databases/sqlite3.yml +19 -0
- data/configs/empty.log +0 -0
- data/configs/initializers/inflections.rb +10 -0
- data/configs/initializers/mime_types.rb +5 -0
- data/configs/initializers/new_rails_defaults.rb +17 -0
- data/configs/lighttpd.conf +54 -0
- data/configs/routes.rb +43 -0
- data/dispatches/dispatch.fcgi +24 -0
- data/dispatches/dispatch.rb +10 -0
- data/dispatches/gateway.cgi +97 -0
- data/doc/README_FOR_APP +2 -0
- data/environments/boot.rb +109 -0
- data/environments/development.rb +16 -0
- data/environments/environment.rb +71 -0
- data/environments/production.rb +22 -0
- data/environments/test.rb +22 -0
- data/fresh_rakefile +10 -0
- data/helpers/application.rb +15 -0
- data/helpers/application_helper.rb +3 -0
- data/helpers/test_helper.rb +38 -0
- data/html/404.html +30 -0
- data/html/422.html +30 -0
- data/html/500.html +30 -0
- data/html/favicon.ico +0 -0
- data/html/images/rails.png +0 -0
- data/html/index.html +274 -0
- data/html/javascripts/application.js +2 -0
- data/html/robots.txt +5 -0
- data/lib/code_statistics.rb +107 -0
- data/lib/commands/about.rb +3 -0
- data/lib/commands/console.rb +32 -0
- data/lib/commands/dbconsole.rb +67 -0
- data/lib/commands/destroy.rb +6 -0
- data/lib/commands/generate.rb +6 -0
- data/lib/commands/ncgi/listener +86 -0
- data/lib/commands/ncgi/tracker +69 -0
- data/lib/commands/performance/benchmarker.rb +24 -0
- data/lib/commands/performance/profiler.rb +50 -0
- data/lib/commands/performance/request.rb +6 -0
- data/lib/commands/plugin.rb +950 -0
- data/lib/commands/process/inspector.rb +68 -0
- data/lib/commands/process/reaper.rb +149 -0
- data/lib/commands/process/spawner.rb +219 -0
- data/lib/commands/process/spinner.rb +57 -0
- data/lib/commands/runner.rb +48 -0
- data/lib/commands/server.rb +39 -0
- data/lib/commands/servers/base.rb +31 -0
- data/lib/commands/servers/lighttpd.rb +94 -0
- data/lib/commands/servers/mongrel.rb +69 -0
- data/lib/commands/servers/new_mongrel.rb +16 -0
- data/lib/commands/servers/webrick.rb +66 -0
- data/lib/commands/update.rb +4 -0
- data/lib/commands.rb +17 -0
- data/lib/console_app.rb +30 -0
- data/lib/console_sandbox.rb +6 -0
- data/lib/console_with_helpers.rb +26 -0
- data/lib/dispatcher.rb +24 -0
- data/lib/fcgi_handler.rb +239 -0
- data/lib/initializer.rb +926 -0
- data/lib/rails/gem_builder.rb +21 -0
- data/lib/rails/gem_dependency.rb +129 -0
- data/lib/rails/mongrel_server/commands.rb +342 -0
- data/lib/rails/mongrel_server/handler.rb +55 -0
- data/lib/rails/plugin/loader.rb +152 -0
- data/lib/rails/plugin/locator.rb +100 -0
- data/lib/rails/plugin.rb +116 -0
- data/lib/rails/version.rb +9 -0
- data/lib/rails_generator/base.rb +263 -0
- data/lib/rails_generator/commands.rb +622 -0
- data/lib/rails_generator/generated_attribute.rb +42 -0
- data/lib/rails_generator/generators/applications/app/USAGE +9 -0
- data/lib/rails_generator/generators/applications/app/app_generator.rb +174 -0
- data/lib/rails_generator/generators/components/controller/USAGE +29 -0
- data/lib/rails_generator/generators/components/controller/controller_generator.rb +37 -0
- data/lib/rails_generator/generators/components/controller/templates/controller.rb +7 -0
- data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +8 -0
- data/lib/rails_generator/generators/components/controller/templates/helper.rb +2 -0
- data/lib/rails_generator/generators/components/controller/templates/view.html.erb +2 -0
- data/lib/rails_generator/generators/components/integration_test/USAGE +8 -0
- data/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb +16 -0
- data/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb +10 -0
- data/lib/rails_generator/generators/components/mailer/USAGE +16 -0
- data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +30 -0
- data/lib/rails_generator/generators/components/mailer/templates/fixture.erb +3 -0
- data/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml +0 -0
- data/lib/rails_generator/generators/components/mailer/templates/mailer.rb +15 -0
- data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +21 -0
- data/lib/rails_generator/generators/components/mailer/templates/view.erb +3 -0
- data/lib/rails_generator/generators/components/mailer/templates/view.rhtml +0 -0
- data/lib/rails_generator/generators/components/migration/USAGE +29 -0
- data/lib/rails_generator/generators/components/migration/migration_generator.rb +20 -0
- data/lib/rails_generator/generators/components/migration/templates/migration.rb +11 -0
- data/lib/rails_generator/generators/components/model/USAGE +27 -0
- data/lib/rails_generator/generators/components/model/model_generator.rb +45 -0
- data/lib/rails_generator/generators/components/model/templates/fixtures.yml +19 -0
- data/lib/rails_generator/generators/components/model/templates/migration.rb +16 -0
- data/lib/rails_generator/generators/components/model/templates/model.rb +2 -0
- data/lib/rails_generator/generators/components/model/templates/unit_test.rb +8 -0
- data/lib/rails_generator/generators/components/observer/USAGE +13 -0
- data/lib/rails_generator/generators/components/observer/observer_generator.rb +16 -0
- data/lib/rails_generator/generators/components/observer/templates/observer.rb +2 -0
- data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +8 -0
- data/lib/rails_generator/generators/components/plugin/USAGE +25 -0
- data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +39 -0
- data/lib/rails_generator/generators/components/plugin/templates/MIT-LICENSE +20 -0
- data/lib/rails_generator/generators/components/plugin/templates/README +13 -0
- data/lib/rails_generator/generators/components/plugin/templates/Rakefile +22 -0
- data/lib/rails_generator/generators/components/plugin/templates/USAGE +8 -0
- data/lib/rails_generator/generators/components/plugin/templates/generator.rb +8 -0
- data/lib/rails_generator/generators/components/plugin/templates/init.rb +1 -0
- data/lib/rails_generator/generators/components/plugin/templates/install.rb +1 -0
- data/lib/rails_generator/generators/components/plugin/templates/plugin.rb +1 -0
- data/lib/rails_generator/generators/components/plugin/templates/tasks.rake +4 -0
- data/lib/rails_generator/generators/components/plugin/templates/uninstall.rb +1 -0
- data/lib/rails_generator/generators/components/plugin/templates/unit_test.rb +8 -0
- data/lib/rails_generator/generators/components/resource/USAGE +23 -0
- data/lib/rails_generator/generators/components/resource/resource_generator.rb +74 -0
- data/lib/rails_generator/generators/components/resource/templates/controller.rb +2 -0
- data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +8 -0
- data/lib/rails_generator/generators/components/resource/templates/helper.rb +2 -0
- data/lib/rails_generator/generators/components/scaffold/USAGE +25 -0
- data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +93 -0
- data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +85 -0
- data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +45 -0
- data/lib/rails_generator/generators/components/scaffold/templates/helper.rb +2 -0
- data/lib/rails_generator/generators/components/scaffold/templates/layout.html.erb +17 -0
- data/lib/rails_generator/generators/components/scaffold/templates/style.css +54 -0
- data/lib/rails_generator/generators/components/scaffold/templates/view_edit.html.erb +18 -0
- data/lib/rails_generator/generators/components/scaffold/templates/view_index.html.erb +24 -0
- data/lib/rails_generator/generators/components/scaffold/templates/view_new.html.erb +17 -0
- data/lib/rails_generator/generators/components/scaffold/templates/view_show.html.erb +10 -0
- data/lib/rails_generator/generators/components/session_migration/USAGE +10 -0
- data/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb +18 -0
- data/lib/rails_generator/generators/components/session_migration/templates/migration.rb +16 -0
- data/lib/rails_generator/lookup.rb +249 -0
- data/lib/rails_generator/manifest.rb +53 -0
- data/lib/rails_generator/options.rb +150 -0
- data/lib/rails_generator/scripts/destroy.rb +30 -0
- data/lib/rails_generator/scripts/generate.rb +7 -0
- data/lib/rails_generator/scripts/update.rb +12 -0
- data/lib/rails_generator/scripts.rb +89 -0
- data/lib/rails_generator/secret_key_generator.rb +164 -0
- data/lib/rails_generator/simple_logger.rb +46 -0
- data/lib/rails_generator/spec.rb +44 -0
- data/lib/rails_generator.rb +43 -0
- data/lib/railties_path.rb +1 -0
- data/lib/ruby_version_check.rb +17 -0
- data/lib/rubyprof_ext.rb +35 -0
- data/lib/source_annotation_extractor.rb +102 -0
- data/lib/tasks/annotations.rake +23 -0
- data/lib/tasks/databases.rake +389 -0
- data/lib/tasks/documentation.rake +80 -0
- data/lib/tasks/framework.rake +105 -0
- data/lib/tasks/gems.rake +64 -0
- data/lib/tasks/log.rake +9 -0
- data/lib/tasks/misc.rake +57 -0
- data/lib/tasks/rails.rb +8 -0
- data/lib/tasks/routes.rake +17 -0
- data/lib/tasks/statistics.rake +18 -0
- data/lib/tasks/testing.rake +118 -0
- data/lib/tasks/tmp.rake +37 -0
- data/lib/test_help.rb +28 -0
- data/lib/webrick_server.rb +165 -0
- metadata +356 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
require 'rbconfig'
|
|
2
|
+
require 'digest/md5'
|
|
3
|
+
require 'rails_generator/secret_key_generator'
|
|
4
|
+
|
|
5
|
+
class AppGenerator < Rails::Generator::Base
|
|
6
|
+
DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
|
|
7
|
+
Config::CONFIG['ruby_install_name'])
|
|
8
|
+
|
|
9
|
+
DATABASES = %w(mysql oracle postgresql sqlite2 sqlite3 frontbase)
|
|
10
|
+
DEFAULT_DATABASE = 'sqlite3'
|
|
11
|
+
|
|
12
|
+
default_options :db => (ENV["RAILS_DEFAULT_DATABASE"] || DEFAULT_DATABASE),
|
|
13
|
+
:shebang => DEFAULT_SHEBANG, :freeze => false
|
|
14
|
+
mandatory_options :source => "#{File.dirname(__FILE__)}/../../../../.."
|
|
15
|
+
|
|
16
|
+
def initialize(runtime_args, runtime_options = {})
|
|
17
|
+
super
|
|
18
|
+
usage if args.empty?
|
|
19
|
+
usage("Databases supported for preconfiguration are: #{DATABASES.join(", ")}") if (options[:db] && !DATABASES.include?(options[:db]))
|
|
20
|
+
@destination_root = args.shift
|
|
21
|
+
@app_name = File.basename(File.expand_path(@destination_root))
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def manifest
|
|
25
|
+
# Use /usr/bin/env if no special shebang was specified
|
|
26
|
+
script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
|
|
27
|
+
dispatcher_options = { :chmod => 0755, :shebang => options[:shebang] }
|
|
28
|
+
|
|
29
|
+
# duplicate CGI::Session#generate_unique_id
|
|
30
|
+
md5 = Digest::MD5.new
|
|
31
|
+
now = Time.now
|
|
32
|
+
md5 << now.to_s
|
|
33
|
+
md5 << String(now.usec)
|
|
34
|
+
md5 << String(rand(0))
|
|
35
|
+
md5 << String($$)
|
|
36
|
+
md5 << @app_name
|
|
37
|
+
|
|
38
|
+
# Do our best to generate a secure secret key for CookieStore
|
|
39
|
+
secret = Rails::SecretKeyGenerator.new(@app_name).generate_secret
|
|
40
|
+
|
|
41
|
+
record do |m|
|
|
42
|
+
# Root directory and all subdirectories.
|
|
43
|
+
m.directory ''
|
|
44
|
+
BASEDIRS.each { |path| m.directory path }
|
|
45
|
+
|
|
46
|
+
# Root
|
|
47
|
+
m.file "fresh_rakefile", "Rakefile"
|
|
48
|
+
m.file "README", "README"
|
|
49
|
+
|
|
50
|
+
# Application
|
|
51
|
+
m.template "helpers/application.rb", "app/controllers/application.rb", :assigns => { :app_name => @app_name, :app_secret => md5.hexdigest }
|
|
52
|
+
m.template "helpers/application_helper.rb", "app/helpers/application_helper.rb"
|
|
53
|
+
m.template "helpers/test_helper.rb", "test/test_helper.rb"
|
|
54
|
+
|
|
55
|
+
# database.yml and routes.rb
|
|
56
|
+
m.template "configs/databases/#{options[:db]}.yml", "config/database.yml", :assigns => {
|
|
57
|
+
:app_name => @app_name,
|
|
58
|
+
:socket => options[:db] == "mysql" ? mysql_socket_location : nil
|
|
59
|
+
}
|
|
60
|
+
m.template "configs/routes.rb", "config/routes.rb"
|
|
61
|
+
|
|
62
|
+
# Initializers
|
|
63
|
+
m.template "configs/initializers/inflections.rb", "config/initializers/inflections.rb"
|
|
64
|
+
m.template "configs/initializers/mime_types.rb", "config/initializers/mime_types.rb"
|
|
65
|
+
m.template "configs/initializers/new_rails_defaults.rb", "config/initializers/new_rails_defaults.rb"
|
|
66
|
+
|
|
67
|
+
# Environments
|
|
68
|
+
m.file "environments/boot.rb", "config/boot.rb"
|
|
69
|
+
m.template "environments/environment.rb", "config/environment.rb", :assigns => { :freeze => options[:freeze], :app_name => @app_name, :app_secret => secret }
|
|
70
|
+
m.file "environments/production.rb", "config/environments/production.rb"
|
|
71
|
+
m.file "environments/development.rb", "config/environments/development.rb"
|
|
72
|
+
m.file "environments/test.rb", "config/environments/test.rb"
|
|
73
|
+
|
|
74
|
+
# Scripts
|
|
75
|
+
%w( about console dbconsole destroy generate performance/benchmarker performance/profiler performance/request process/reaper process/spawner process/inspector runner server plugin ).each do |file|
|
|
76
|
+
m.file "bin/#{file}", "script/#{file}", script_options
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Dispatches
|
|
80
|
+
m.file "dispatches/dispatch.rb", "public/dispatch.rb", dispatcher_options
|
|
81
|
+
m.file "dispatches/dispatch.rb", "public/dispatch.cgi", dispatcher_options
|
|
82
|
+
m.file "dispatches/dispatch.fcgi", "public/dispatch.fcgi", dispatcher_options
|
|
83
|
+
|
|
84
|
+
# HTML files
|
|
85
|
+
%w(404 422 500 index).each do |file|
|
|
86
|
+
m.template "html/#{file}.html", "public/#{file}.html"
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
m.template "html/favicon.ico", "public/favicon.ico"
|
|
90
|
+
m.template "html/robots.txt", "public/robots.txt"
|
|
91
|
+
m.file "html/images/rails.png", "public/images/rails.png"
|
|
92
|
+
|
|
93
|
+
# Javascripts
|
|
94
|
+
m.file "html/javascripts/application.js", "public/javascripts/application.js"
|
|
95
|
+
|
|
96
|
+
# Docs
|
|
97
|
+
m.file "doc/README_FOR_APP", "doc/README_FOR_APP"
|
|
98
|
+
|
|
99
|
+
# Logs
|
|
100
|
+
%w(server production development test).each { |file|
|
|
101
|
+
m.file "configs/empty.log", "log/#{file}.log", :chmod => 0666
|
|
102
|
+
}
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
protected
|
|
107
|
+
def banner
|
|
108
|
+
"Usage: #{$0} /path/to/your/app [options]"
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def add_options!(opt)
|
|
112
|
+
opt.separator ''
|
|
113
|
+
opt.separator 'Options:'
|
|
114
|
+
opt.on("-r", "--ruby=path", String,
|
|
115
|
+
"Path to the Ruby binary of your choice (otherwise scripts use env, dispatchers current path).",
|
|
116
|
+
"Default: #{DEFAULT_SHEBANG}") { |v| options[:shebang] = v }
|
|
117
|
+
|
|
118
|
+
opt.on("-d", "--database=name", String,
|
|
119
|
+
"Preconfigure for selected database (options: #{DATABASES.join('/')}).",
|
|
120
|
+
"Default: #{DEFAULT_DATABASE}") { |v| options[:db] = v }
|
|
121
|
+
|
|
122
|
+
opt.on("-f", "--freeze",
|
|
123
|
+
"Freeze Rails in vendor/rails from the gems generating the skeleton",
|
|
124
|
+
"Default: false") { |v| options[:freeze] = v }
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def mysql_socket_location
|
|
128
|
+
MYSQL_SOCKET_LOCATIONS.find { |f| File.exist?(f) } unless RUBY_PLATFORM =~ /(:?mswin|mingw)/
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
# Installation skeleton. Intermediate directories are automatically
|
|
133
|
+
# created so don't sweat their absence here.
|
|
134
|
+
BASEDIRS = %w(
|
|
135
|
+
app/controllers
|
|
136
|
+
app/helpers
|
|
137
|
+
app/models
|
|
138
|
+
app/views/layouts
|
|
139
|
+
config/environments
|
|
140
|
+
config/initializers
|
|
141
|
+
db
|
|
142
|
+
doc
|
|
143
|
+
lib
|
|
144
|
+
lib/tasks
|
|
145
|
+
log
|
|
146
|
+
public/images
|
|
147
|
+
public/javascripts
|
|
148
|
+
public/stylesheets
|
|
149
|
+
script/performance
|
|
150
|
+
script/process
|
|
151
|
+
test/fixtures
|
|
152
|
+
test/functional
|
|
153
|
+
test/integration
|
|
154
|
+
test/unit
|
|
155
|
+
vendor
|
|
156
|
+
vendor/plugins
|
|
157
|
+
tmp/sessions
|
|
158
|
+
tmp/sockets
|
|
159
|
+
tmp/cache
|
|
160
|
+
tmp/pids
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
MYSQL_SOCKET_LOCATIONS = [
|
|
164
|
+
"/tmp/mysql.sock", # default
|
|
165
|
+
"/var/run/mysqld/mysqld.sock", # debian/gentoo
|
|
166
|
+
"/var/tmp/mysql.sock", # freebsd
|
|
167
|
+
"/var/lib/mysql/mysql.sock", # fedora
|
|
168
|
+
"/opt/local/lib/mysql/mysql.sock", # fedora
|
|
169
|
+
"/opt/local/var/run/mysqld/mysqld.sock", # mac + darwinports + mysql
|
|
170
|
+
"/opt/local/var/run/mysql4/mysqld.sock", # mac + darwinports + mysql4
|
|
171
|
+
"/opt/local/var/run/mysql5/mysqld.sock", # mac + darwinports + mysql5
|
|
172
|
+
"/opt/lampp/var/mysql/mysql.sock" # xampp for linux
|
|
173
|
+
]
|
|
174
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Description:
|
|
2
|
+
Stubs out a new controller and its views. Pass the controller name, either
|
|
3
|
+
CamelCased or under_scored, and a list of views as arguments.
|
|
4
|
+
|
|
5
|
+
To create a controller within a module, specify the controller name as a
|
|
6
|
+
path like 'parent_module/controller_name'.
|
|
7
|
+
|
|
8
|
+
This generates a controller class in app/controllers, view templates in
|
|
9
|
+
app/views/controller_name, a helper class in app/helpers, and a functional
|
|
10
|
+
test suite in test/functional.
|
|
11
|
+
|
|
12
|
+
Example:
|
|
13
|
+
`./script/generate controller CreditCard open debit credit close`
|
|
14
|
+
|
|
15
|
+
Credit card controller with URLs like /credit_card/debit.
|
|
16
|
+
Controller: app/controllers/credit_card_controller.rb
|
|
17
|
+
Views: app/views/credit_card/debit.html.erb [...]
|
|
18
|
+
Helper: app/helpers/credit_card_helper.rb
|
|
19
|
+
Test: test/functional/credit_card_controller_test.rb
|
|
20
|
+
|
|
21
|
+
Modules Example:
|
|
22
|
+
`./script/generate controller 'admin/credit_card' suspend late_fee`
|
|
23
|
+
|
|
24
|
+
Credit card admin controller with URLs /admin/credit_card/suspend.
|
|
25
|
+
Controller: app/controllers/admin/credit_card_controller.rb
|
|
26
|
+
Views: app/views/admin/credit_card/debit.html.erb [...]
|
|
27
|
+
Helper: app/helpers/admin/credit_card_helper.rb
|
|
28
|
+
Test: test/functional/admin/credit_card_controller_test.rb
|
|
29
|
+
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
class ControllerGenerator < Rails::Generator::NamedBase
|
|
2
|
+
def manifest
|
|
3
|
+
record do |m|
|
|
4
|
+
# Check for class naming collisions.
|
|
5
|
+
m.class_collisions class_path, "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper"
|
|
6
|
+
|
|
7
|
+
# Controller, helper, views, and test directories.
|
|
8
|
+
m.directory File.join('app/controllers', class_path)
|
|
9
|
+
m.directory File.join('app/helpers', class_path)
|
|
10
|
+
m.directory File.join('app/views', class_path, file_name)
|
|
11
|
+
m.directory File.join('test/functional', class_path)
|
|
12
|
+
|
|
13
|
+
# Controller class, functional test, and helper class.
|
|
14
|
+
m.template 'controller.rb',
|
|
15
|
+
File.join('app/controllers',
|
|
16
|
+
class_path,
|
|
17
|
+
"#{file_name}_controller.rb")
|
|
18
|
+
|
|
19
|
+
m.template 'functional_test.rb',
|
|
20
|
+
File.join('test/functional',
|
|
21
|
+
class_path,
|
|
22
|
+
"#{file_name}_controller_test.rb")
|
|
23
|
+
|
|
24
|
+
m.template 'helper.rb',
|
|
25
|
+
File.join('app/helpers',
|
|
26
|
+
class_path,
|
|
27
|
+
"#{file_name}_helper.rb")
|
|
28
|
+
|
|
29
|
+
# View template for each action.
|
|
30
|
+
actions.each do |action|
|
|
31
|
+
path = File.join('app/views', class_path, file_name, "#{action}.html.erb")
|
|
32
|
+
m.template 'view.html.erb', path,
|
|
33
|
+
:assigns => { :action => action, :path => path }
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Description:
|
|
2
|
+
Stubs out a new integration test. Pass the name of the test, either
|
|
3
|
+
CamelCased or under_scored, as an argument. The new test class is
|
|
4
|
+
generated in test/integration/testname_test.rb
|
|
5
|
+
|
|
6
|
+
Example:
|
|
7
|
+
`./script/generate integration_test GeneralStories` creates a GeneralStories
|
|
8
|
+
integration test in test/integration/general_stories_test.rb
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class IntegrationTestGenerator < Rails::Generator::NamedBase
|
|
2
|
+
default_options :skip_migration => false
|
|
3
|
+
|
|
4
|
+
def manifest
|
|
5
|
+
record do |m|
|
|
6
|
+
# Check for class naming collisions.
|
|
7
|
+
m.class_collisions class_path, class_name, "#{class_name}Test"
|
|
8
|
+
|
|
9
|
+
# integration test directory
|
|
10
|
+
m.directory File.join('test/integration', class_path)
|
|
11
|
+
|
|
12
|
+
# integration test stub
|
|
13
|
+
m.template 'integration_test.rb', File.join('test/integration', class_path, "#{file_name}_test.rb")
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Description:
|
|
2
|
+
Stubs out a new mailer and its views. Pass the mailer name, either
|
|
3
|
+
CamelCased or under_scored, and an optional list of emails as arguments.
|
|
4
|
+
|
|
5
|
+
This generates a mailer class in app/models, view templates in
|
|
6
|
+
app/views/mailer_name, a unit test in test/unit, and fixtures in
|
|
7
|
+
test/fixtures.
|
|
8
|
+
|
|
9
|
+
Example:
|
|
10
|
+
`./script/generate mailer Notifications signup forgot_password invoice`
|
|
11
|
+
|
|
12
|
+
creates a Notifications mailer class, views, test, and fixtures:
|
|
13
|
+
Mailer: app/models/notifications.rb
|
|
14
|
+
Views: app/views/notifications/signup.erb [...]
|
|
15
|
+
Test: test/unit/test/unit/notifications_test.rb
|
|
16
|
+
Fixtures: test/fixtures/notifications/signup [...]
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
class MailerGenerator < Rails::Generator::NamedBase
|
|
2
|
+
def manifest
|
|
3
|
+
record do |m|
|
|
4
|
+
# Check for class naming collisions.
|
|
5
|
+
m.class_collisions class_path, class_name, "#{class_name}Test"
|
|
6
|
+
|
|
7
|
+
# Mailer, view, test, and fixture directories.
|
|
8
|
+
m.directory File.join('app/models', class_path)
|
|
9
|
+
m.directory File.join('app/views', file_path)
|
|
10
|
+
m.directory File.join('test/unit', class_path)
|
|
11
|
+
m.directory File.join('test/fixtures', file_path)
|
|
12
|
+
|
|
13
|
+
# Mailer class and unit test.
|
|
14
|
+
m.template "mailer.rb", File.join('app/models', class_path, "#{file_name}.rb")
|
|
15
|
+
m.template "unit_test.rb", File.join('test/unit', class_path, "#{file_name}_test.rb")
|
|
16
|
+
|
|
17
|
+
# View template and fixture for each action.
|
|
18
|
+
actions.each do |action|
|
|
19
|
+
relative_path = File.join(file_path, action)
|
|
20
|
+
view_path = File.join('app/views', "#{relative_path}.erb")
|
|
21
|
+
fixture_path = File.join('test/fixtures', relative_path)
|
|
22
|
+
|
|
23
|
+
m.template "view.erb", view_path,
|
|
24
|
+
:assigns => { :action => action, :path => view_path }
|
|
25
|
+
m.template "fixture.erb", fixture_path,
|
|
26
|
+
:assigns => { :action => action, :path => view_path }
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class <%= class_name %> < ActionMailer::Base
|
|
2
|
+
|
|
3
|
+
<% for action in actions -%>
|
|
4
|
+
|
|
5
|
+
def <%= action %>(sent_at = Time.now)
|
|
6
|
+
subject '<%= class_name %>#<%= action %>'
|
|
7
|
+
recipients ''
|
|
8
|
+
from ''
|
|
9
|
+
sent_on sent_at
|
|
10
|
+
|
|
11
|
+
body :greeting => 'Hi,'
|
|
12
|
+
end
|
|
13
|
+
<% end -%>
|
|
14
|
+
|
|
15
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class <%= class_name %>Test < ActionMailer::TestCase
|
|
4
|
+
tests <%= class_name %>
|
|
5
|
+
<% for action in actions -%>
|
|
6
|
+
def test_<%= action %>
|
|
7
|
+
@expected.subject = '<%= class_name %>#<%= action %>'
|
|
8
|
+
@expected.body = read_fixture('<%= action %>')
|
|
9
|
+
@expected.date = Time.now
|
|
10
|
+
|
|
11
|
+
assert_equal @expected.encoded, <%= class_name %>.create_<%= action %>(@expected.date).encoded
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
<% end -%>
|
|
15
|
+
<% if actions.blank? -%>
|
|
16
|
+
# replace this with your real tests
|
|
17
|
+
def test_truth
|
|
18
|
+
assert true
|
|
19
|
+
end
|
|
20
|
+
<% end -%>
|
|
21
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Description:
|
|
2
|
+
Stubs out a new database migration. Pass the migration name, either
|
|
3
|
+
CamelCased or under_scored, and an optional list of attribute pairs as arguments.
|
|
4
|
+
|
|
5
|
+
A migration class is generated in db/migrate prefixed by a timestamp of the current date and time.
|
|
6
|
+
|
|
7
|
+
You can name your migration in either of these formats to generate add/remove
|
|
8
|
+
column lines from supplied attributes: AddColumnsToTable or RemoveColumnsFromTable
|
|
9
|
+
|
|
10
|
+
Example:
|
|
11
|
+
`./script/generate migration AddSslFlag`
|
|
12
|
+
|
|
13
|
+
If the current date is May 14, 2008 and the current time 09:09:12, this creates the AddSslFlag migration
|
|
14
|
+
db/migrate/20080514090912_add_ssl_flag.rb
|
|
15
|
+
|
|
16
|
+
`./script/generate migration AddTitleBodyToPost title:string body:text published:boolean`
|
|
17
|
+
|
|
18
|
+
This will create the AddTitleBodyToPost in db/migrate/20080514090912_add_title_body_to_post.rb with
|
|
19
|
+
this in the Up migration:
|
|
20
|
+
|
|
21
|
+
add_column :posts, :title, :string
|
|
22
|
+
add_column :posts, :body, :text
|
|
23
|
+
add_column :posts, :published, :boolean
|
|
24
|
+
|
|
25
|
+
And this in the Down migration:
|
|
26
|
+
|
|
27
|
+
remove_column :posts, :published
|
|
28
|
+
remove_column :posts, :body
|
|
29
|
+
remove_column :posts, :title
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class MigrationGenerator < Rails::Generator::NamedBase
|
|
2
|
+
def manifest
|
|
3
|
+
record do |m|
|
|
4
|
+
m.migration_template 'migration.rb', 'db/migrate', :assigns => get_local_assigns
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
def get_local_assigns
|
|
11
|
+
returning(assigns = {}) do
|
|
12
|
+
if class_name.underscore =~ /^(add|remove)_.*_(?:to|from)_(.*)/
|
|
13
|
+
assigns[:migration_action] = $1
|
|
14
|
+
assigns[:table_name] = $2.pluralize
|
|
15
|
+
else
|
|
16
|
+
assigns[:attributes] = []
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
class <%= class_name.underscore.camelize %> < ActiveRecord::Migration
|
|
2
|
+
def self.up<% attributes.each do |attribute| %>
|
|
3
|
+
<%= migration_action %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'add' %>, :<%= attribute.type %><% end -%>
|
|
4
|
+
<%- end %>
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def self.down<% attributes.reverse.each do |attribute| %>
|
|
8
|
+
<%= migration_action == 'add' ? 'remove' : 'add' %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'remove' %>, :<%= attribute.type %><% end -%>
|
|
9
|
+
<%- end %>
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Description:
|
|
2
|
+
Stubs out a new model. Pass the model name, either CamelCased or
|
|
3
|
+
under_scored, and an optional list of attribute pairs as arguments.
|
|
4
|
+
|
|
5
|
+
Attribute pairs are column_name:sql_type arguments specifying the
|
|
6
|
+
model's attributes. Timestamps are added by default, so you don't have to
|
|
7
|
+
specify them by hand as 'created_at:datetime updated_at:datetime'.
|
|
8
|
+
|
|
9
|
+
You don't have to think up every attribute up front, but it helps to
|
|
10
|
+
sketch out a few so you can start working with the model immediately.
|
|
11
|
+
|
|
12
|
+
This generates a model class in app/models, a unit test in test/unit,
|
|
13
|
+
a test fixture in test/fixtures/singular_name.yml, and a migration in
|
|
14
|
+
db/migrate.
|
|
15
|
+
|
|
16
|
+
Examples:
|
|
17
|
+
`./script/generate model account`
|
|
18
|
+
|
|
19
|
+
creates an Account model, test, fixture, and migration:
|
|
20
|
+
Model: app/models/account.rb
|
|
21
|
+
Test: test/unit/account_test.rb
|
|
22
|
+
Fixtures: test/fixtures/accounts.yml
|
|
23
|
+
Migration: db/migrate/XXX_add_accounts.rb
|
|
24
|
+
|
|
25
|
+
`./script/generate model post title:string body:text published:boolean`
|
|
26
|
+
|
|
27
|
+
creates a Post model with a string title, text body, and published flag.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
class ModelGenerator < Rails::Generator::NamedBase
|
|
2
|
+
default_options :skip_timestamps => false, :skip_migration => false, :skip_fixture => false
|
|
3
|
+
|
|
4
|
+
def manifest
|
|
5
|
+
record do |m|
|
|
6
|
+
# Check for class naming collisions.
|
|
7
|
+
m.class_collisions class_path, class_name, "#{class_name}Test"
|
|
8
|
+
|
|
9
|
+
# Model, test, and fixture directories.
|
|
10
|
+
m.directory File.join('app/models', class_path)
|
|
11
|
+
m.directory File.join('test/unit', class_path)
|
|
12
|
+
m.directory File.join('test/fixtures', class_path)
|
|
13
|
+
|
|
14
|
+
# Model class, unit test, and fixtures.
|
|
15
|
+
m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
|
|
16
|
+
m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb")
|
|
17
|
+
|
|
18
|
+
unless options[:skip_fixture]
|
|
19
|
+
m.template 'fixtures.yml', File.join('test/fixtures', "#{table_name}.yml")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
unless options[:skip_migration]
|
|
23
|
+
m.migration_template 'migration.rb', 'db/migrate', :assigns => {
|
|
24
|
+
:migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
|
|
25
|
+
}, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
protected
|
|
31
|
+
def banner
|
|
32
|
+
"Usage: #{$0} #{spec.name} ModelName [field:type, field:type]"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def add_options!(opt)
|
|
36
|
+
opt.separator ''
|
|
37
|
+
opt.separator 'Options:'
|
|
38
|
+
opt.on("--skip-timestamps",
|
|
39
|
+
"Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v }
|
|
40
|
+
opt.on("--skip-migration",
|
|
41
|
+
"Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
|
|
42
|
+
opt.on("--skip-fixture",
|
|
43
|
+
"Don't generation a fixture file for this model") { |v| options[:skip_fixture] = v}
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
|
2
|
+
|
|
3
|
+
<% unless attributes.empty? -%>
|
|
4
|
+
one:
|
|
5
|
+
<% for attribute in attributes -%>
|
|
6
|
+
<%= attribute.name %>: <%= attribute.default %>
|
|
7
|
+
<% end -%>
|
|
8
|
+
|
|
9
|
+
two:
|
|
10
|
+
<% for attribute in attributes -%>
|
|
11
|
+
<%= attribute.name %>: <%= attribute.default %>
|
|
12
|
+
<% end -%>
|
|
13
|
+
<% else -%>
|
|
14
|
+
# one:
|
|
15
|
+
# column: value
|
|
16
|
+
#
|
|
17
|
+
# two:
|
|
18
|
+
# column: value
|
|
19
|
+
<% end -%>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class <%= migration_name %> < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
create_table :<%= table_name %> do |t|
|
|
4
|
+
<% for attribute in attributes -%>
|
|
5
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
|
6
|
+
<% end -%>
|
|
7
|
+
<% unless options[:skip_timestamps] %>
|
|
8
|
+
t.timestamps
|
|
9
|
+
<% end -%>
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.down
|
|
14
|
+
drop_table :<%= table_name %>
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Description:
|
|
2
|
+
Stubs out a new observer. Pass the observer name, either CamelCased or
|
|
3
|
+
under_scored, as an argument.
|
|
4
|
+
|
|
5
|
+
The generator creates an observer class in app/models and a unit test in
|
|
6
|
+
test/unit.
|
|
7
|
+
|
|
8
|
+
Example:
|
|
9
|
+
`./script/generate observer Account`
|
|
10
|
+
|
|
11
|
+
creates an Account observer and unit test:
|
|
12
|
+
Observer: app/models/account_observer.rb
|
|
13
|
+
Test: test/unit/account_observer_test.rb
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class ObserverGenerator < Rails::Generator::NamedBase
|
|
2
|
+
def manifest
|
|
3
|
+
record do |m|
|
|
4
|
+
# Check for class naming collisions.
|
|
5
|
+
m.class_collisions class_path, "#{class_name}Observer", "#{class_name}ObserverTest"
|
|
6
|
+
|
|
7
|
+
# Observer, and test directories.
|
|
8
|
+
m.directory File.join('app/models', class_path)
|
|
9
|
+
m.directory File.join('test/unit', class_path)
|
|
10
|
+
|
|
11
|
+
# Observer class and unit test fixtures.
|
|
12
|
+
m.template 'observer.rb', File.join('app/models', class_path, "#{file_name}_observer.rb")
|
|
13
|
+
m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_observer_test.rb")
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|