railties 4.0.13 → 4.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +155 -385
- data/README.rdoc +1 -1
- data/bin/rails +1 -1
- data/lib/rails.rb +11 -13
- data/lib/rails/all.rb +1 -0
- data/lib/rails/api/task.rb +9 -12
- data/lib/rails/app_rails_loader.rb +2 -2
- data/lib/rails/application.rb +154 -149
- data/lib/rails/application/configuration.rb +1 -14
- data/lib/rails/application/default_middleware_stack.rb +99 -0
- data/lib/rails/application/finisher.rb +2 -0
- data/lib/rails/application_controller.rb +16 -0
- data/lib/rails/cli.rb +1 -2
- data/lib/rails/commands.rb +2 -94
- data/lib/rails/commands/application.rb +2 -28
- data/lib/rails/commands/commands_tasks.rb +174 -0
- data/lib/rails/commands/console.rb +2 -2
- data/lib/rails/commands/dbconsole.rb +1 -1
- data/lib/rails/commands/plugin.rb +23 -0
- data/lib/rails/commands/runner.rb +1 -1
- data/lib/rails/commands/server.rb +46 -30
- data/lib/rails/configuration.rb +4 -1
- data/lib/rails/console/helpers.rb +6 -0
- data/lib/rails/engine.rb +29 -18
- data/lib/rails/engine/commands.rb +1 -1
- data/lib/rails/engine/railties.rb +0 -8
- data/lib/rails/generators.rb +4 -3
- data/lib/rails/generators/actions.rb +1 -1
- data/lib/rails/generators/active_model.rb +0 -8
- data/lib/rails/generators/app_base.rb +213 -74
- data/lib/rails/generators/base.rb +17 -16
- data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +1 -1
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb +1 -3
- data/lib/rails/generators/migration.rb +18 -26
- data/lib/rails/generators/named_base.rb +4 -7
- data/lib/rails/generators/rails/app/app_generator.rb +91 -5
- data/lib/rails/generators/rails/app/templates/Gemfile +20 -15
- data/lib/rails/generators/rails/app/templates/Rakefile +1 -1
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +2 -0
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +5 -3
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +5 -1
- data/lib/rails/generators/rails/app/templates/config/application.rb +2 -0
- data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml +7 -10
- data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +11 -31
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +25 -29
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +8 -10
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +8 -11
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +6 -3
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +8 -22
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +7 -9
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +9 -12
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml +8 -8
- data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml +7 -17
- data/lib/rails/generators/rails/app/templates/config/environment.rb +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +2 -5
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +1 -4
- data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/routes.rb +1 -1
- data/lib/rails/generators/rails/app/templates/config/{initializers/secret_token.rb.tt → secrets.yml} +10 -2
- data/lib/rails/generators/rails/app/templates/public/404.html +20 -11
- data/lib/rails/generators/rails/app/templates/public/422.html +20 -11
- data/lib/rails/generators/rails/app/templates/public/500.html +19 -10
- data/lib/rails/generators/rails/controller/USAGE +1 -0
- data/lib/rails/generators/rails/controller/controller_generator.rb +35 -1
- data/lib/rails/generators/rails/generator/USAGE +1 -0
- data/lib/rails/generators/rails/generator/generator_generator.rb +2 -0
- data/lib/rails/generators/rails/model/USAGE +5 -5
- data/lib/rails/generators/rails/{plugin_new → plugin}/USAGE +0 -0
- data/lib/rails/generators/rails/{plugin_new/plugin_new_generator.rb → plugin/plugin_generator.rb} +10 -4
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/%name%.gemspec +1 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/Gemfile +16 -1
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/MIT-LICENSE +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/README.rdoc +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/Rakefile +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/controllers/%name%/application_controller.rb.tt +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/helpers/%name%/application_helper.rb.tt +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/mailers/.empty_directory +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/models/.empty_directory +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/views/layouts/%name%/application.html.erb.tt +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/bin/rails.tt +0 -4
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/config/routes.rb +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/gitignore +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/lib/%name%.rb +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/lib/%name%/engine.rb +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/lib/%name%/version.rb +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/lib/tasks/%name%_tasks.rake +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/rails/application.rb +1 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/rails/boot.rb +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/rails/javascripts.js +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/rails/routes.rb +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/rails/stylesheets.css +5 -3
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/test/%name%_test.rb +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/test/integration/navigation_test.rb +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/test/test_helper.rb +0 -0
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +1 -1
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +2 -2
- data/lib/rails/generators/resource_helpers.rb +20 -5
- data/lib/rails/generators/test_unit/generator/generator_generator.rb +26 -0
- data/lib/rails/generators/test_unit/generator/templates/generator_test.rb +16 -0
- data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +8 -1
- data/lib/rails/generators/test_unit/mailer/templates/preview.rb +11 -0
- data/lib/rails/generators/testing/assertions.rb +1 -1
- data/lib/rails/generators/testing/behaviour.rb +3 -13
- data/lib/rails/info.rb +5 -3
- data/lib/rails/info_controller.rb +5 -15
- data/lib/rails/mailers_controller.rb +73 -0
- data/lib/rails/paths.rb +13 -18
- data/lib/rails/rack/debugger.rb +2 -2
- data/lib/rails/rack/logger.rb +1 -1
- data/lib/rails/railtie.rb +38 -2
- data/lib/rails/source_annotation_extractor.rb +2 -2
- data/lib/rails/tasks.rb +0 -2
- data/lib/rails/tasks/documentation.rake +0 -5
- data/lib/rails/tasks/engine.rake +1 -1
- data/lib/rails/tasks/framework.rake +2 -12
- data/lib/rails/templates/layouts/application.html.erb +2 -2
- data/lib/rails/templates/rails/mailers/email.html.erb +98 -0
- data/lib/rails/templates/rails/mailers/index.html.erb +8 -0
- data/lib/rails/templates/rails/mailers/mailer.html.erb +6 -0
- data/lib/rails/test_help.rb +4 -1
- data/lib/rails/test_unit/sub_test_task.rb +44 -3
- data/lib/rails/test_unit/testing.rake +9 -111
- data/lib/rails/version.rb +3 -3
- data/lib/rails/welcome_controller.rb +4 -3
- metadata +99 -76
- data/lib/rails/commands/plugin_new.rb +0 -9
- data/lib/rails/generators/actions/create_migration.rb +0 -68
@@ -61,7 +61,6 @@ module Rails
|
|
61
61
|
@assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/#{Rails.env}/" ]
|
62
62
|
@assets.js_compressor = nil
|
63
63
|
@assets.css_compressor = nil
|
64
|
-
@assets.initialize_on_precompile = true
|
65
64
|
@assets.logger = nil
|
66
65
|
end
|
67
66
|
|
@@ -77,6 +76,7 @@ module Rails
|
|
77
76
|
@paths ||= begin
|
78
77
|
paths = super
|
79
78
|
paths.add "config/database", with: "config/database.yml"
|
79
|
+
paths.add "config/secrets", with: "config/secrets.yml"
|
80
80
|
paths.add "config/environment", with: "config/environment.rb"
|
81
81
|
paths.add "lib/templates"
|
82
82
|
paths.add "log", with: "log/#{Rails.env}.log"
|
@@ -88,16 +88,6 @@ module Rails
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
def threadsafe!
|
92
|
-
message = "config.threadsafe! is deprecated. Rails applications " \
|
93
|
-
"behave by default as thread safe in production as long as config.cache_classes and " \
|
94
|
-
"config.eager_load are set to true"
|
95
|
-
ActiveSupport::Deprecation.warn message
|
96
|
-
@cache_classes = true
|
97
|
-
@eager_load = true
|
98
|
-
self
|
99
|
-
end
|
100
|
-
|
101
91
|
# Loads and returns the configuration of the database.
|
102
92
|
def database_configuration
|
103
93
|
yaml = paths["config/database"].first
|
@@ -151,9 +141,6 @@ module Rails
|
|
151
141
|
end
|
152
142
|
end
|
153
143
|
|
154
|
-
def whiny_nils=(*)
|
155
|
-
ActiveSupport::Deprecation.warn "config.whiny_nils option is deprecated and no longer works"
|
156
|
-
end
|
157
144
|
end
|
158
145
|
end
|
159
146
|
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module Rails
|
2
|
+
class Application
|
3
|
+
class DefaultMiddlewareStack
|
4
|
+
attr_reader :config, :paths, :app
|
5
|
+
|
6
|
+
def initialize(app, config, paths)
|
7
|
+
@app = app
|
8
|
+
@config = config
|
9
|
+
@paths = paths
|
10
|
+
end
|
11
|
+
|
12
|
+
def build_stack
|
13
|
+
ActionDispatch::MiddlewareStack.new.tap do |middleware|
|
14
|
+
if config.force_ssl
|
15
|
+
middleware.use ::ActionDispatch::SSL, config.ssl_options
|
16
|
+
end
|
17
|
+
|
18
|
+
middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header
|
19
|
+
|
20
|
+
if config.serve_static_assets
|
21
|
+
middleware.use ::ActionDispatch::Static, paths["public"].first, config.static_cache_control
|
22
|
+
end
|
23
|
+
|
24
|
+
if rack_cache = load_rack_cache
|
25
|
+
require "action_dispatch/http/rack_cache"
|
26
|
+
middleware.use ::Rack::Cache, rack_cache
|
27
|
+
end
|
28
|
+
|
29
|
+
middleware.use ::Rack::Lock unless allow_concurrency?
|
30
|
+
middleware.use ::Rack::Runtime
|
31
|
+
middleware.use ::Rack::MethodOverride
|
32
|
+
middleware.use ::ActionDispatch::RequestId
|
33
|
+
|
34
|
+
# Must come after Rack::MethodOverride to properly log overridden methods
|
35
|
+
middleware.use ::Rails::Rack::Logger, config.log_tags
|
36
|
+
middleware.use ::ActionDispatch::ShowExceptions, show_exceptions_app
|
37
|
+
middleware.use ::ActionDispatch::DebugExceptions, app
|
38
|
+
middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies
|
39
|
+
|
40
|
+
unless config.cache_classes
|
41
|
+
middleware.use ::ActionDispatch::Reloader, lambda { reload_dependencies? }
|
42
|
+
end
|
43
|
+
|
44
|
+
middleware.use ::ActionDispatch::Callbacks
|
45
|
+
middleware.use ::ActionDispatch::Cookies
|
46
|
+
|
47
|
+
if config.session_store
|
48
|
+
if config.force_ssl && !config.session_options.key?(:secure)
|
49
|
+
config.session_options[:secure] = true
|
50
|
+
end
|
51
|
+
middleware.use config.session_store, config.session_options
|
52
|
+
middleware.use ::ActionDispatch::Flash
|
53
|
+
end
|
54
|
+
|
55
|
+
middleware.use ::ActionDispatch::ParamsParser
|
56
|
+
middleware.use ::Rack::Head
|
57
|
+
middleware.use ::Rack::ConditionalGet
|
58
|
+
middleware.use ::Rack::ETag, "no-cache"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def reload_dependencies?
|
65
|
+
config.reload_classes_only_on_change != true || app.reloaders.map(&:updated?).any?
|
66
|
+
end
|
67
|
+
|
68
|
+
def allow_concurrency?
|
69
|
+
config.allow_concurrency.nil? ? config.cache_classes : config.allow_concurrency
|
70
|
+
end
|
71
|
+
|
72
|
+
def load_rack_cache
|
73
|
+
rack_cache = config.action_dispatch.rack_cache
|
74
|
+
return unless rack_cache
|
75
|
+
|
76
|
+
begin
|
77
|
+
require 'rack/cache'
|
78
|
+
rescue LoadError => error
|
79
|
+
error.message << ' Be sure to add rack-cache to your Gemfile'
|
80
|
+
raise
|
81
|
+
end
|
82
|
+
|
83
|
+
if rack_cache == true
|
84
|
+
{
|
85
|
+
metastore: "rails:/",
|
86
|
+
entitystore: "rails:/",
|
87
|
+
verbose: false
|
88
|
+
}
|
89
|
+
else
|
90
|
+
rack_cache
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def show_exceptions_app
|
95
|
+
config.exceptions_app || ActionDispatch::PublicExceptions.new(Rails.public_path)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -22,6 +22,8 @@ module Rails
|
|
22
22
|
initializer :add_builtin_route do |app|
|
23
23
|
if Rails.env.development?
|
24
24
|
app.routes.append do
|
25
|
+
get '/rails/mailers' => "rails/mailers#index"
|
26
|
+
get '/rails/mailers/*path' => "rails/mailers#preview"
|
25
27
|
get '/rails/info/properties' => "rails/info#properties"
|
26
28
|
get '/rails/info/routes' => "rails/info#routes"
|
27
29
|
get '/rails/info' => "rails/info#index"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Rails::ApplicationController < ActionController::Base # :nodoc:
|
2
|
+
self.view_paths = File.expand_path('../templates', __FILE__)
|
3
|
+
layout 'application'
|
4
|
+
|
5
|
+
protected
|
6
|
+
|
7
|
+
def require_local!
|
8
|
+
unless local_request?
|
9
|
+
render text: '<p>For security purposes, this information is only available to local requests.</p>', status: :forbidden
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def local_request?
|
14
|
+
Rails.application.config.consider_all_requests_local || request.local?
|
15
|
+
end
|
16
|
+
end
|
data/lib/rails/cli.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'rbconfig'
|
2
1
|
require 'rails/app_rails_loader'
|
3
2
|
|
4
3
|
# If we are inside a Rails application this method performs an exec and thus
|
@@ -10,7 +9,7 @@ Signal.trap("INT") { puts; exit(1) }
|
|
10
9
|
|
11
10
|
if ARGV.first == 'plugin'
|
12
11
|
ARGV.shift
|
13
|
-
require 'rails/commands/
|
12
|
+
require 'rails/commands/plugin'
|
14
13
|
else
|
15
14
|
require 'rails/commands/application'
|
16
15
|
end
|
data/lib/rails/commands.rb
CHANGED
@@ -9,101 +9,9 @@ aliases = {
|
|
9
9
|
"r" => "runner"
|
10
10
|
}
|
11
11
|
|
12
|
-
help_message = <<-EOT
|
13
|
-
Usage: rails COMMAND [ARGS]
|
14
|
-
|
15
|
-
The most common rails commands are:
|
16
|
-
generate Generate new code (short-cut alias: "g")
|
17
|
-
console Start the Rails console (short-cut alias: "c")
|
18
|
-
server Start the Rails server (short-cut alias: "s")
|
19
|
-
dbconsole Start a console for the database specified in config/database.yml
|
20
|
-
(short-cut alias: "db")
|
21
|
-
new Create a new Rails application. "rails new my_app" creates a
|
22
|
-
new application called MyApp in "./my_app"
|
23
|
-
|
24
|
-
In addition to those, there are:
|
25
|
-
application Generate the Rails application code
|
26
|
-
destroy Undo code generated with "generate" (short-cut alias: "d")
|
27
|
-
plugin new Generates skeleton for developing a Rails plugin
|
28
|
-
runner Run a piece of code in the application environment (short-cut alias: "r")
|
29
|
-
|
30
|
-
All commands can be run with -h (or --help) for more information.
|
31
|
-
EOT
|
32
|
-
|
33
|
-
|
34
12
|
command = ARGV.shift
|
35
13
|
command = aliases[command] || command
|
36
14
|
|
37
|
-
|
38
|
-
when 'plugin'
|
39
|
-
require "rails/commands/plugin_new"
|
40
|
-
when 'generate', 'destroy'
|
41
|
-
require 'rails/generators'
|
42
|
-
|
43
|
-
require APP_PATH
|
44
|
-
Rails.application.require_environment!
|
45
|
-
|
46
|
-
Rails.application.load_generators
|
47
|
-
|
48
|
-
require "rails/commands/#{command}"
|
49
|
-
|
50
|
-
when 'console'
|
51
|
-
require 'rails/commands/console'
|
52
|
-
options = Rails::Console.parse_arguments(ARGV)
|
53
|
-
|
54
|
-
# RAILS_ENV needs to be set before config/application is required
|
55
|
-
ENV['RAILS_ENV'] = options[:environment] if options[:environment]
|
56
|
-
|
57
|
-
# shift ARGV so IRB doesn't freak
|
58
|
-
ARGV.shift if ARGV.first && ARGV.first[0] != '-'
|
59
|
-
|
60
|
-
require APP_PATH
|
61
|
-
Rails.application.require_environment!
|
62
|
-
Rails::Console.start(Rails.application, options)
|
63
|
-
|
64
|
-
when 'server'
|
65
|
-
# Change to the application's path if there is no config.ru file in current directory.
|
66
|
-
# This allows us to run `rails server` from other directories, but still get
|
67
|
-
# the main config.ru and properly set the tmp directory.
|
68
|
-
Dir.chdir(File.expand_path('../../', APP_PATH)) unless File.exist?(File.expand_path("config.ru"))
|
69
|
-
|
70
|
-
require 'rails/commands/server'
|
71
|
-
Rails::Server.new.tap do |server|
|
72
|
-
# We need to require application after the server sets environment,
|
73
|
-
# otherwise the --environment option given to the server won't propagate.
|
74
|
-
require APP_PATH
|
75
|
-
Dir.chdir(Rails.application.root)
|
76
|
-
server.start
|
77
|
-
end
|
78
|
-
|
79
|
-
when 'dbconsole'
|
80
|
-
require 'rails/commands/dbconsole'
|
81
|
-
Rails::DBConsole.start
|
82
|
-
|
83
|
-
when 'application', 'runner'
|
84
|
-
require "rails/commands/#{command}"
|
85
|
-
|
86
|
-
when 'new'
|
87
|
-
if %w(-h --help).include?(ARGV.first)
|
88
|
-
require 'rails/commands/application'
|
89
|
-
else
|
90
|
-
puts "Can't initialize a new Rails application within the directory of another, please change to a non-Rails directory first.\n"
|
91
|
-
puts "Type 'rails' for help."
|
92
|
-
exit(1)
|
93
|
-
end
|
94
|
-
|
95
|
-
when '--version', '-v'
|
96
|
-
ARGV.unshift '--version'
|
97
|
-
require 'rails/commands/application'
|
98
|
-
|
99
|
-
when '-h', '--help'
|
100
|
-
puts help_message
|
15
|
+
require 'rails/commands/commands_tasks'
|
101
16
|
|
102
|
-
|
103
|
-
puts "Error: Command '#{command}' not recognized"
|
104
|
-
if %x{rake #{command} --dry-run 2>&1 } && $?.success?
|
105
|
-
puts "Did you mean: `$ rake #{command}` ?\n\n"
|
106
|
-
end
|
107
|
-
puts help_message
|
108
|
-
exit(1)
|
109
|
-
end
|
17
|
+
Rails::CommandsTasks.new(ARGV).run_command!(command)
|
@@ -1,30 +1,3 @@
|
|
1
|
-
require 'rails/version'
|
2
|
-
|
3
|
-
if ['--version', '-v'].include?(ARGV.first)
|
4
|
-
puts "Rails #{Rails::VERSION::STRING}"
|
5
|
-
exit(0)
|
6
|
-
end
|
7
|
-
|
8
|
-
if ARGV.first != "new"
|
9
|
-
ARGV[0] = "--help"
|
10
|
-
else
|
11
|
-
ARGV.shift
|
12
|
-
unless ARGV.delete("--no-rc")
|
13
|
-
customrc = ARGV.index{ |x| x.include?("--rc=") }
|
14
|
-
railsrc = if customrc
|
15
|
-
File.expand_path(ARGV.delete_at(customrc).gsub(/--rc=/, ""))
|
16
|
-
else
|
17
|
-
File.join(File.expand_path("~"), '.railsrc')
|
18
|
-
end
|
19
|
-
if File.exist?(railsrc)
|
20
|
-
extra_args_string = File.read(railsrc)
|
21
|
-
extra_args = extra_args_string.split(/\n+/).map {|l| l.split}.flatten
|
22
|
-
puts "Using #{extra_args.join(" ")} from #{railsrc}"
|
23
|
-
ARGV.insert(1, *extra_args)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
1
|
require 'rails/generators'
|
29
2
|
require 'rails/generators/rails/app/app_generator'
|
30
3
|
|
@@ -40,4 +13,5 @@ module Rails
|
|
40
13
|
end
|
41
14
|
end
|
42
15
|
|
43
|
-
Rails::Generators::
|
16
|
+
args = Rails::Generators::ARGVScrubber.new(ARGV).prepare!
|
17
|
+
Rails::Generators::AppGenerator.start args
|
@@ -0,0 +1,174 @@
|
|
1
|
+
module Rails
|
2
|
+
# This is a class which takes in a rails command and initiates the appropriate
|
3
|
+
# initiation sequence.
|
4
|
+
#
|
5
|
+
# Warning: This class mutates ARGV because some commands require manipulating
|
6
|
+
# it before they are run.
|
7
|
+
class CommandsTasks # :nodoc:
|
8
|
+
attr_reader :argv
|
9
|
+
|
10
|
+
HELP_MESSAGE = <<-EOT
|
11
|
+
Usage: rails COMMAND [ARGS]
|
12
|
+
|
13
|
+
The most common rails commands are:
|
14
|
+
generate Generate new code (short-cut alias: "g")
|
15
|
+
console Start the Rails console (short-cut alias: "c")
|
16
|
+
server Start the Rails server (short-cut alias: "s")
|
17
|
+
dbconsole Start a console for the database specified in config/database.yml
|
18
|
+
(short-cut alias: "db")
|
19
|
+
new Create a new Rails application. "rails new my_app" creates a
|
20
|
+
new application called MyApp in "./my_app"
|
21
|
+
|
22
|
+
In addition to those, there are:
|
23
|
+
application Generate the Rails application code
|
24
|
+
destroy Undo code generated with "generate" (short-cut alias: "d")
|
25
|
+
plugin new Generates skeleton for developing a Rails plugin
|
26
|
+
runner Run a piece of code in the application environment (short-cut alias: "r")
|
27
|
+
|
28
|
+
All commands can be run with -h (or --help) for more information.
|
29
|
+
EOT
|
30
|
+
|
31
|
+
COMMAND_WHITELIST = %(plugin generate destroy console server dbconsole application runner new version help)
|
32
|
+
|
33
|
+
def initialize(argv)
|
34
|
+
@argv = argv
|
35
|
+
end
|
36
|
+
|
37
|
+
def run_command!(command)
|
38
|
+
command = parse_command(command)
|
39
|
+
if COMMAND_WHITELIST.include?(command)
|
40
|
+
send(command)
|
41
|
+
else
|
42
|
+
write_error_message(command)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def plugin
|
47
|
+
require_command!("plugin")
|
48
|
+
end
|
49
|
+
|
50
|
+
def generate
|
51
|
+
generate_or_destroy(:generate)
|
52
|
+
end
|
53
|
+
|
54
|
+
def destroy
|
55
|
+
generate_or_destroy(:destroy)
|
56
|
+
end
|
57
|
+
|
58
|
+
def console
|
59
|
+
require_command!("console")
|
60
|
+
options = Rails::Console.parse_arguments(argv)
|
61
|
+
|
62
|
+
# RAILS_ENV needs to be set before config/application is required
|
63
|
+
ENV['RAILS_ENV'] = options[:environment] if options[:environment]
|
64
|
+
|
65
|
+
# shift ARGV so IRB doesn't freak
|
66
|
+
shift_argv!
|
67
|
+
|
68
|
+
require_application_and_environment!
|
69
|
+
Rails::Console.start(Rails.application, options)
|
70
|
+
end
|
71
|
+
|
72
|
+
def server
|
73
|
+
set_application_directory!
|
74
|
+
require_command!("server")
|
75
|
+
|
76
|
+
Rails::Server.new.tap do |server|
|
77
|
+
# We need to require application after the server sets environment,
|
78
|
+
# otherwise the --environment option given to the server won't propagate.
|
79
|
+
require APP_PATH
|
80
|
+
Dir.chdir(Rails.application.root)
|
81
|
+
server.start
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def dbconsole
|
86
|
+
require_command!("dbconsole")
|
87
|
+
Rails::DBConsole.start
|
88
|
+
end
|
89
|
+
|
90
|
+
def application
|
91
|
+
require_command!("application")
|
92
|
+
end
|
93
|
+
|
94
|
+
def runner
|
95
|
+
require_command!("runner")
|
96
|
+
end
|
97
|
+
|
98
|
+
def new
|
99
|
+
if %w(-h --help).include?(argv.first)
|
100
|
+
require_command!("application")
|
101
|
+
else
|
102
|
+
exit_with_initialization_warning!
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def version
|
107
|
+
argv.unshift '--version'
|
108
|
+
require_command!("application")
|
109
|
+
end
|
110
|
+
|
111
|
+
def help
|
112
|
+
write_help_message
|
113
|
+
end
|
114
|
+
|
115
|
+
private
|
116
|
+
|
117
|
+
def exit_with_initialization_warning!
|
118
|
+
puts "Can't initialize a new Rails application within the directory of another, please change to a non-Rails directory first.\n"
|
119
|
+
puts "Type 'rails' for help."
|
120
|
+
exit(1)
|
121
|
+
end
|
122
|
+
|
123
|
+
def shift_argv!
|
124
|
+
argv.shift if argv.first && argv.first[0] != '-'
|
125
|
+
end
|
126
|
+
|
127
|
+
def require_command!(command)
|
128
|
+
require "rails/commands/#{command}"
|
129
|
+
end
|
130
|
+
|
131
|
+
def generate_or_destroy(command)
|
132
|
+
require 'rails/generators'
|
133
|
+
require_application_and_environment!
|
134
|
+
Rails.application.load_generators
|
135
|
+
require "rails/commands/#{command}"
|
136
|
+
end
|
137
|
+
|
138
|
+
# Change to the application's path if there is no config.ru file in current directory.
|
139
|
+
# This allows us to run `rails server` from other directories, but still get
|
140
|
+
# the main config.ru and properly set the tmp directory.
|
141
|
+
def set_application_directory!
|
142
|
+
Dir.chdir(File.expand_path('../../', APP_PATH)) unless File.exist?(File.expand_path("config.ru"))
|
143
|
+
end
|
144
|
+
|
145
|
+
def require_application_and_environment!
|
146
|
+
require APP_PATH
|
147
|
+
Rails.application.require_environment!
|
148
|
+
end
|
149
|
+
|
150
|
+
def write_help_message
|
151
|
+
puts HELP_MESSAGE
|
152
|
+
end
|
153
|
+
|
154
|
+
def write_error_message(command)
|
155
|
+
puts "Error: Command '#{command}' not recognized"
|
156
|
+
if %x{rake #{command} --dry-run 2>&1 } && $?.success?
|
157
|
+
puts "Did you mean: `$ rake #{command}` ?\n\n"
|
158
|
+
end
|
159
|
+
write_help_message
|
160
|
+
exit(1)
|
161
|
+
end
|
162
|
+
|
163
|
+
def parse_command(command)
|
164
|
+
case command
|
165
|
+
when '--version', '-v'
|
166
|
+
'version'
|
167
|
+
when '--help', '-h'
|
168
|
+
'help'
|
169
|
+
else
|
170
|
+
command
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|