railties 5.0.7.2 → 5.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +77 -567
  3. data/MIT-LICENSE +1 -1
  4. data/RDOC_MAIN.rdoc +3 -3
  5. data/README.rdoc +1 -1
  6. data/exe/rails +2 -2
  7. data/lib/rails.rb +18 -18
  8. data/lib/rails/all.rb +1 -1
  9. data/lib/rails/api/generator.rb +28 -0
  10. data/lib/rails/api/task.rb +54 -42
  11. data/lib/rails/app_loader.rb +9 -9
  12. data/lib/rails/application.rb +30 -35
  13. data/lib/rails/application/bootstrap.rb +13 -7
  14. data/lib/rails/application/configuration.rb +30 -53
  15. data/lib/rails/application/default_middleware_stack.rb +3 -5
  16. data/lib/rails/application/finisher.rb +16 -7
  17. data/lib/rails/application/routes_reloader.rb +16 -1
  18. data/lib/rails/application_controller.rb +10 -10
  19. data/lib/rails/backtrace_cleaner.rb +5 -5
  20. data/lib/rails/cli.rb +7 -5
  21. data/lib/rails/code_statistics.rb +16 -17
  22. data/lib/rails/code_statistics_calculator.rb +3 -3
  23. data/lib/rails/command.rb +111 -0
  24. data/lib/rails/command/actions.rb +42 -0
  25. data/lib/rails/command/base.rb +149 -0
  26. data/lib/rails/command/behavior.rb +123 -0
  27. data/lib/rails/command/environment_argument.rb +34 -0
  28. data/lib/rails/commands.rb +2 -4
  29. data/lib/rails/commands/application/application_command.rb +29 -0
  30. data/lib/rails/commands/console/console_command.rb +89 -0
  31. data/lib/rails/commands/dbconsole/dbconsole_command.rb +155 -0
  32. data/lib/rails/commands/destroy/destroy_command.rb +21 -0
  33. data/lib/rails/commands/generate/generate_command.rb +23 -0
  34. data/lib/rails/commands/help/USAGE +15 -0
  35. data/lib/rails/commands/help/help_command.rb +13 -0
  36. data/lib/rails/commands/new/new_command.rb +15 -0
  37. data/lib/rails/commands/plugin/plugin_command.rb +43 -0
  38. data/lib/rails/commands/rake/rake_command.rb +49 -0
  39. data/lib/rails/commands/runner/USAGE +17 -0
  40. data/lib/rails/commands/runner/runner_command.rb +46 -0
  41. data/lib/rails/commands/secrets/USAGE +52 -0
  42. data/lib/rails/commands/secrets/secrets_command.rb +36 -0
  43. data/lib/rails/commands/server/server_command.rb +177 -0
  44. data/lib/rails/commands/test/test_command.rb +20 -0
  45. data/lib/rails/commands/version/version_command.rb +9 -0
  46. data/lib/rails/configuration.rb +7 -7
  47. data/lib/rails/console/app.rb +4 -4
  48. data/lib/rails/dev_caching.rb +8 -8
  49. data/lib/rails/engine.rb +62 -63
  50. data/lib/rails/engine/commands.rb +6 -13
  51. data/lib/rails/engine/configuration.rb +2 -2
  52. data/lib/rails/gem_version.rb +3 -3
  53. data/lib/rails/generators.rb +229 -313
  54. data/lib/rails/generators/actions.rb +20 -21
  55. data/lib/rails/generators/actions/create_migration.rb +24 -25
  56. data/lib/rails/generators/active_model.rb +3 -3
  57. data/lib/rails/generators/app_base.rb +123 -93
  58. data/lib/rails/generators/base.rb +32 -33
  59. data/lib/rails/generators/css/assets/assets_generator.rb +1 -1
  60. data/lib/rails/generators/erb.rb +14 -14
  61. data/lib/rails/generators/erb/controller/controller_generator.rb +1 -1
  62. data/lib/rails/generators/erb/mailer/mailer_generator.rb +12 -12
  63. data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +3 -3
  64. data/lib/rails/generators/generated_attribute.rb +27 -27
  65. data/lib/rails/generators/js/assets/assets_generator.rb +1 -1
  66. data/lib/rails/generators/migration.rb +8 -8
  67. data/lib/rails/generators/model_helpers.rb +2 -2
  68. data/lib/rails/generators/named_base.rb +56 -56
  69. data/lib/rails/generators/rails/app/app_generator.rb +98 -81
  70. data/lib/rails/generators/rails/app/templates/Gemfile +7 -2
  71. data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -2
  72. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +6 -4
  73. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.js +1 -1
  74. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +2 -2
  75. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +1 -1
  76. data/lib/rails/generators/rails/app/templates/bin/{setup → setup.tt} +6 -0
  77. data/lib/rails/generators/rails/app/templates/bin/{update → update.tt} +2 -1
  78. data/lib/rails/generators/rails/app/templates/bin/yarn +9 -0
  79. data/lib/rails/generators/rails/app/templates/config/cable.yml +1 -0
  80. data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml +1 -0
  81. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +1 -0
  82. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +1 -0
  83. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +2 -1
  84. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +1 -0
  85. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +1 -0
  86. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +2 -2
  87. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -0
  88. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +1 -1
  89. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml +1 -1
  90. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +1 -1
  91. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +10 -1
  92. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +1 -1
  93. data/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb +4 -6
  94. data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +8 -3
  95. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults.rb.tt +6 -5
  96. data/lib/rails/generators/rails/app/templates/config/locales/en.yml +10 -0
  97. data/lib/rails/generators/rails/app/templates/config/puma.rb +16 -7
  98. data/lib/rails/generators/rails/app/templates/config/secrets.yml +12 -2
  99. data/lib/rails/generators/rails/app/templates/gitignore +5 -1
  100. data/lib/rails/generators/rails/app/templates/package.json +5 -0
  101. data/lib/rails/generators/rails/app/templates/public/404.html +6 -6
  102. data/lib/rails/generators/rails/app/templates/public/422.html +6 -6
  103. data/lib/rails/generators/rails/app/templates/public/500.html +6 -6
  104. data/lib/rails/generators/rails/app/templates/public/robots.txt +0 -4
  105. data/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb +5 -0
  106. data/lib/rails/generators/rails/app/templates/test/test_helper.rb +0 -1
  107. data/lib/rails/generators/rails/assets/assets_generator.rb +10 -10
  108. data/lib/rails/generators/rails/controller/controller_generator.rb +15 -12
  109. data/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb +66 -0
  110. data/lib/rails/generators/rails/encrypted_secrets/templates/config/secrets.yml.enc +3 -0
  111. data/lib/rails/generators/rails/generator/generator_generator.rb +2 -3
  112. data/lib/rails/generators/rails/helper/helper_generator.rb +1 -1
  113. data/lib/rails/generators/rails/model/model_generator.rb +1 -1
  114. data/lib/rails/generators/rails/plugin/plugin_generator.rb +21 -26
  115. data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +1 -0
  116. data/lib/rails/generators/rails/plugin/templates/bin/test.tt +3 -9
  117. data/lib/rails/generators/rails/plugin/templates/test/application_system_test_case.rb +5 -0
  118. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb +0 -3
  119. data/lib/rails/generators/rails/resource/resource_generator.rb +2 -2
  120. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +5 -1
  121. data/lib/rails/generators/rails/scaffold/templates/scaffold.css +4 -8
  122. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +2 -3
  123. data/lib/rails/generators/rails/system_test/USAGE +10 -0
  124. data/lib/rails/generators/rails/system_test/system_test_generator.rb +7 -0
  125. data/lib/rails/generators/rails/task/task_generator.rb +1 -2
  126. data/lib/rails/generators/resource_helpers.rb +13 -10
  127. data/lib/rails/generators/test_case.rb +5 -6
  128. data/lib/rails/generators/test_unit.rb +1 -1
  129. data/lib/rails/generators/test_unit/controller/controller_generator.rb +3 -3
  130. data/lib/rails/generators/test_unit/generator/generator_generator.rb +3 -3
  131. data/lib/rails/generators/test_unit/helper/helper_generator.rb +1 -1
  132. data/lib/rails/generators/test_unit/integration/integration_generator.rb +2 -2
  133. data/lib/rails/generators/test_unit/job/job_generator.rb +3 -3
  134. data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +5 -5
  135. data/lib/rails/generators/test_unit/model/model_generator.rb +3 -4
  136. data/lib/rails/generators/test_unit/plugin/plugin_generator.rb +2 -2
  137. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +3 -3
  138. data/lib/rails/generators/test_unit/system/system_generator.rb +17 -0
  139. data/lib/rails/generators/test_unit/system/templates/application_system_test_case.rb +5 -0
  140. data/lib/rails/generators/test_unit/system/templates/system_test.rb +9 -0
  141. data/lib/rails/generators/testing/assertions.rb +4 -4
  142. data/lib/rails/generators/testing/behaviour.rb +20 -21
  143. data/lib/rails/info.rb +20 -20
  144. data/lib/rails/info_controller.rb +15 -15
  145. data/lib/rails/initializable.rb +6 -2
  146. data/lib/rails/mailers_controller.rb +11 -11
  147. data/lib/rails/paths.rb +4 -5
  148. data/lib/rails/plugin/test.rb +7 -0
  149. data/lib/rails/rack/logger.rb +44 -46
  150. data/lib/rails/railtie.rb +41 -38
  151. data/lib/rails/railtie/configurable.rb +6 -6
  152. data/lib/rails/railtie/configuration.rb +1 -1
  153. data/lib/rails/ruby_version_check.rb +1 -1
  154. data/lib/rails/secrets.rb +111 -0
  155. data/lib/rails/source_annotation_extractor.rb +15 -9
  156. data/lib/rails/tasks.rb +3 -2
  157. data/lib/rails/tasks/annotations.rake +3 -3
  158. data/lib/rails/tasks/dev.rake +2 -2
  159. data/lib/rails/tasks/engine.rake +4 -4
  160. data/lib/rails/tasks/framework.rake +4 -18
  161. data/lib/rails/tasks/initializers.rake +1 -1
  162. data/lib/rails/tasks/log.rake +14 -10
  163. data/lib/rails/tasks/middleware.rake +1 -1
  164. data/lib/rails/tasks/misc.rake +10 -10
  165. data/lib/rails/tasks/restart.rake +4 -4
  166. data/lib/rails/tasks/routes.rake +3 -12
  167. data/lib/rails/tasks/statistics.rake +3 -3
  168. data/lib/rails/tasks/tmp.rake +7 -7
  169. data/lib/rails/tasks/yarn.rake +11 -0
  170. data/lib/rails/templates/rails/mailers/email.html.erb +4 -1
  171. data/lib/rails/test_help.rb +28 -10
  172. data/lib/rails/test_unit/line_filtering.rb +69 -3
  173. data/lib/rails/test_unit/minitest_plugin.rb +139 -0
  174. data/lib/rails/test_unit/railtie.rb +2 -1
  175. data/lib/rails/test_unit/reporter.rb +3 -8
  176. data/lib/rails/test_unit/test_requirer.rb +28 -0
  177. data/lib/rails/test_unit/testing.rake +19 -14
  178. data/lib/rails/version.rb +1 -1
  179. data/lib/rails/welcome_controller.rb +1 -1
  180. metadata +53 -30
  181. data/lib/minitest/rails_plugin.rb +0 -49
  182. data/lib/rails/commands/application.rb +0 -17
  183. data/lib/rails/commands/commands_tasks.rb +0 -180
  184. data/lib/rails/commands/console.rb +0 -68
  185. data/lib/rails/commands/console_helper.rb +0 -34
  186. data/lib/rails/commands/dbconsole.rb +0 -173
  187. data/lib/rails/commands/destroy.rb +0 -11
  188. data/lib/rails/commands/generate.rb +0 -13
  189. data/lib/rails/commands/plugin.rb +0 -23
  190. data/lib/rails/commands/rake_proxy.rb +0 -41
  191. data/lib/rails/commands/runner.rb +0 -71
  192. data/lib/rails/commands/server.rb +0 -163
  193. data/lib/rails/commands/test.rb +0 -10
  194. data/lib/rails/engine/commands_tasks.rb +0 -118
  195. data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +0 -3
  196. data/lib/rails/rack/debugger.rb +0 -3
  197. data/lib/rails/test_unit/runner.rb +0 -141
@@ -0,0 +1,34 @@
1
+ require "active_support"
2
+
3
+ module Rails
4
+ module Command
5
+ module EnvironmentArgument #:nodoc:
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ argument :environment, optional: true, banner: "environment"
10
+ end
11
+
12
+ private
13
+ def extract_environment_option_from_argument
14
+ if environment
15
+ self.options = options.merge(environment: acceptable_environment(environment))
16
+ elsif !options[:environment]
17
+ self.options = options.merge(environment: Rails::Command.environment)
18
+ end
19
+ end
20
+
21
+ def acceptable_environment(env = nil)
22
+ if available_environments.include? env
23
+ env
24
+ else
25
+ %w( production development test ).detect { |e| e =~ /^#{env}/ } || env
26
+ end
27
+ end
28
+
29
+ def available_environments
30
+ Dir["config/environments/*.rb"].map { |fname| File.basename(fname, ".*") }
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,4 +1,4 @@
1
- ARGV << '--help' if ARGV.empty?
1
+ require "rails/command"
2
2
 
3
3
  aliases = {
4
4
  "g" => "generate",
@@ -13,6 +13,4 @@ aliases = {
13
13
  command = ARGV.shift
14
14
  command = aliases[command] || command
15
15
 
16
- require 'rails/commands/commands_tasks'
17
-
18
- Rails::CommandsTasks.new(ARGV).run_command!(command)
16
+ Rails::Command.invoke command, ARGV
@@ -0,0 +1,29 @@
1
+ require "rails/generators"
2
+ require "rails/generators/rails/app/app_generator"
3
+
4
+ module Rails
5
+ module Generators
6
+ class AppGenerator # :nodoc:
7
+ # We want to exit on failure to be kind to other libraries
8
+ # This is only when accessing via CLI
9
+ def self.exit_on_failure?
10
+ true
11
+ end
12
+ end
13
+ end
14
+
15
+ module Command
16
+ class ApplicationCommand < Base # :nodoc:
17
+ hide_command!
18
+
19
+ def help
20
+ perform # Punt help output to the generator.
21
+ end
22
+
23
+ def perform(*args)
24
+ Rails::Generators::AppGenerator.start \
25
+ Rails::Generators::ARGVScrubber.new(args).prepare!
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,89 @@
1
+ require "irb"
2
+ require "irb/completion"
3
+
4
+ require "rails/command/environment_argument"
5
+
6
+ module Rails
7
+ class Console
8
+ module BacktraceCleaner
9
+ def filter_backtrace(bt)
10
+ if result = super
11
+ Rails.backtrace_cleaner.filter([result]).first
12
+ end
13
+ end
14
+ end
15
+
16
+ def self.start(*args)
17
+ new(*args).start
18
+ end
19
+
20
+ attr_reader :options, :app, :console
21
+
22
+ def initialize(app, options = {})
23
+ @app = app
24
+ @options = options
25
+
26
+ app.sandbox = sandbox?
27
+ app.load_console
28
+
29
+ @console = app.config.console || IRB
30
+
31
+ if @console == IRB
32
+ IRB::WorkSpace.prepend(BacktraceCleaner)
33
+ end
34
+ end
35
+
36
+ def sandbox?
37
+ options[:sandbox]
38
+ end
39
+
40
+ def environment
41
+ options[:environment]
42
+ end
43
+ alias_method :environment?, :environment
44
+
45
+ def set_environment!
46
+ Rails.env = environment
47
+ end
48
+
49
+ def start
50
+ set_environment! if environment?
51
+
52
+ if sandbox?
53
+ puts "Loading #{Rails.env} environment in sandbox (Rails #{Rails.version})"
54
+ puts "Any modifications you make will be rolled back on exit"
55
+ else
56
+ puts "Loading #{Rails.env} environment (Rails #{Rails.version})"
57
+ end
58
+
59
+ if defined?(console::ExtendCommandBundle)
60
+ console::ExtendCommandBundle.include(Rails::ConsoleMethods)
61
+ end
62
+ console.start
63
+ end
64
+ end
65
+
66
+ module Command
67
+ class ConsoleCommand < Base # :nodoc:
68
+ include EnvironmentArgument
69
+
70
+ class_option :sandbox, aliases: "-s", type: :boolean, default: false,
71
+ desc: "Rollback database modifications on exit."
72
+
73
+ class_option :environment, aliases: "-e", type: :string,
74
+ desc: "Specifies the environment to run this console under (test/development/production)."
75
+
76
+ def perform
77
+ extract_environment_option_from_argument
78
+
79
+ # RAILS_ENV needs to be set before config/application is required.
80
+ ENV["RAILS_ENV"] = options[:environment]
81
+
82
+ ARGV.clear # Clear ARGV so IRB doesn't freak.
83
+
84
+ require_application_and_environment!
85
+ Rails::Console.start(Rails.application, options)
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,155 @@
1
+ require "rails/command/environment_argument"
2
+
3
+ module Rails
4
+ class DBConsole
5
+ def self.start(*args)
6
+ new(*args).start
7
+ end
8
+
9
+ def initialize(options = {})
10
+ @options = options
11
+ end
12
+
13
+ def start
14
+ ENV["RAILS_ENV"] = @options[:environment] || environment
15
+
16
+ case config["adapter"]
17
+ when /^(jdbc)?mysql/
18
+ args = {
19
+ "host" => "--host",
20
+ "port" => "--port",
21
+ "socket" => "--socket",
22
+ "username" => "--user",
23
+ "encoding" => "--default-character-set",
24
+ "sslca" => "--ssl-ca",
25
+ "sslcert" => "--ssl-cert",
26
+ "sslcapath" => "--ssl-capath",
27
+ "sslcipher" => "--ssl-cipher",
28
+ "sslkey" => "--ssl-key"
29
+ }.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact
30
+
31
+ if config["password"] && @options["include_password"]
32
+ args << "--password=#{config['password']}"
33
+ elsif config["password"] && !config["password"].to_s.empty?
34
+ args << "-p"
35
+ end
36
+
37
+ args << config["database"]
38
+
39
+ find_cmd_and_exec(["mysql", "mysql5"], *args)
40
+
41
+ when /^postgres|^postgis/
42
+ ENV["PGUSER"] = config["username"] if config["username"]
43
+ ENV["PGHOST"] = config["host"] if config["host"]
44
+ ENV["PGPORT"] = config["port"].to_s if config["port"]
45
+ ENV["PGPASSWORD"] = config["password"].to_s if config["password"] && @options["include_password"]
46
+ find_cmd_and_exec("psql", config["database"])
47
+
48
+ when "sqlite3"
49
+ args = []
50
+
51
+ args << "-#{@options['mode']}" if @options["mode"]
52
+ args << "-header" if @options["header"]
53
+ args << File.expand_path(config["database"], Rails.respond_to?(:root) ? Rails.root : nil)
54
+
55
+ find_cmd_and_exec("sqlite3", *args)
56
+
57
+ when "oracle", "oracle_enhanced"
58
+ logon = ""
59
+
60
+ if config["username"]
61
+ logon = config["username"]
62
+ logon << "/#{config['password']}" if config["password"] && @options["include_password"]
63
+ logon << "@#{config['database']}" if config["database"]
64
+ end
65
+
66
+ find_cmd_and_exec("sqlplus", logon)
67
+
68
+ when "sqlserver"
69
+ args = []
70
+
71
+ args += ["-D", "#{config['database']}"] if config["database"]
72
+ args += ["-U", "#{config['username']}"] if config["username"]
73
+ args += ["-P", "#{config['password']}"] if config["password"]
74
+
75
+ if config["host"]
76
+ host_arg = "#{config['host']}"
77
+ host_arg << ":#{config['port']}" if config["port"]
78
+ args += ["-S", host_arg]
79
+ end
80
+
81
+ find_cmd_and_exec("sqsh", *args)
82
+
83
+ else
84
+ abort "Unknown command-line client for #{config['database']}."
85
+ end
86
+ end
87
+
88
+ def config
89
+ @config ||= begin
90
+ if configurations[environment].blank?
91
+ raise ActiveRecord::AdapterNotSpecified, "'#{environment}' database is not configured. Available configuration: #{configurations.inspect}"
92
+ else
93
+ configurations[environment]
94
+ end
95
+ end
96
+ end
97
+
98
+ def environment
99
+ Rails.respond_to?(:env) ? Rails.env : Rails::Command.environment
100
+ end
101
+
102
+ private
103
+ def configurations # :doc:
104
+ require APP_PATH
105
+ ActiveRecord::Base.configurations = Rails.application.config.database_configuration
106
+ ActiveRecord::Base.configurations
107
+ end
108
+
109
+ def find_cmd_and_exec(commands, *args) # :doc:
110
+ commands = Array(commands)
111
+
112
+ dirs_on_path = ENV["PATH"].to_s.split(File::PATH_SEPARATOR)
113
+ unless (ext = RbConfig::CONFIG["EXEEXT"]).empty?
114
+ commands = commands.map { |cmd| "#{cmd}#{ext}" }
115
+ end
116
+
117
+ full_path_command = nil
118
+ found = commands.detect do |cmd|
119
+ dirs_on_path.detect do |path|
120
+ full_path_command = File.join(path, cmd)
121
+ File.file?(full_path_command) && File.executable?(full_path_command)
122
+ end
123
+ end
124
+
125
+ if found
126
+ exec full_path_command, *args
127
+ else
128
+ abort("Couldn't find database client: #{commands.join(', ')}. Check your $PATH and try again.")
129
+ end
130
+ end
131
+ end
132
+
133
+ module Command
134
+ class DbconsoleCommand < Base # :nodoc:
135
+ include EnvironmentArgument
136
+
137
+ class_option :include_password, aliases: "-p", type: :boolean,
138
+ desc: "Automatically provide the password from database.yml"
139
+
140
+ class_option :mode, enum: %w( html list line column ), type: :string,
141
+ desc: "Automatically put the sqlite3 database in the specified mode (html, list, line, column)."
142
+
143
+ class_option :header, type: :string
144
+
145
+ class_option :environment, aliases: "-e", type: :string,
146
+ desc: "Specifies the environment to run this console under (test/development/production)."
147
+
148
+ def perform
149
+ extract_environment_option_from_argument
150
+
151
+ Rails::DBConsole.start(options)
152
+ end
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,21 @@
1
+ require "rails/generators"
2
+
3
+ module Rails
4
+ module Command
5
+ class DestroyCommand < Base # :nodoc:
6
+ def help
7
+ Rails::Generators.help self.class.command_name
8
+ end
9
+
10
+ def perform(*)
11
+ generator = args.shift
12
+ return help unless generator
13
+
14
+ require_application_and_environment!
15
+ Rails.application.load_generators
16
+
17
+ Rails::Generators.invoke generator, args, behavior: :revoke, destination_root: Rails.root
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ require "rails/generators"
2
+
3
+ module Rails
4
+ module Command
5
+ class GenerateCommand < Base # :nodoc:
6
+ def help
7
+ Rails::Generators.help self.class.command_name
8
+ end
9
+
10
+ def perform(*)
11
+ generator = args.shift
12
+ return help unless generator
13
+
14
+ require_application_and_environment!
15
+ load_generators
16
+
17
+ ARGV.shift
18
+
19
+ Rails::Generators.invoke generator, args, behavior: :invoke, destination_root: Rails::Command.root
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ The most common rails commands are:
2
+ generate Generate new code (short-cut alias: "g")
3
+ console Start the Rails console (short-cut alias: "c")
4
+ server Start the Rails server (short-cut alias: "s")
5
+ test Run tests (short-cut alias: "t")
6
+ dbconsole Start a console for the database specified in config/database.yml
7
+ (short-cut alias: "db")
8
+ <% unless engine? %>
9
+ new Create a new Rails application. "rails new my_app" creates a
10
+ new application called MyApp in "./my_app"
11
+ <% end %>
12
+
13
+ All commands can be run with -h (or --help) for more information.
14
+ In addition to those commands, there are:
15
+
@@ -0,0 +1,13 @@
1
+ module Rails
2
+ module Command
3
+ class HelpCommand < Base # :nodoc:
4
+ hide_command!
5
+
6
+ def help(*)
7
+ puts self.class.desc
8
+
9
+ Rails::Command.print_commands
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ module Rails
2
+ module Command
3
+ class NewCommand < Base # :nodoc:
4
+ def help
5
+ Rails::Command.invoke :application, [ "--help" ]
6
+ end
7
+
8
+ def perform(*)
9
+ puts "Can't initialize a new Rails application within the directory of another, please change to a non-Rails directory first.\n"
10
+ puts "Type 'rails' for help."
11
+ exit 1
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,43 @@
1
+ module Rails
2
+ module Command
3
+ class PluginCommand < Base # :nodoc:
4
+ hide_command!
5
+
6
+ def help
7
+ run_plugin_generator %w( --help )
8
+ end
9
+
10
+ def self.banner(*) # :nodoc:
11
+ "#{executable} new [options]"
12
+ end
13
+
14
+ class_option :rc, type: :string, default: File.join("~", ".railsrc"),
15
+ desc: "Initialize the plugin command with previous defaults. Uses .railsrc in your home directory by default."
16
+
17
+ class_option :no_rc, desc: "Skip evaluating .railsrc."
18
+
19
+ def perform(type = nil, *plugin_args)
20
+ plugin_args << "--help" unless type == "new"
21
+
22
+ unless options.key?("no_rc") # Thor's not so indifferent access hash.
23
+ railsrc = File.expand_path(options[:rc])
24
+
25
+ if File.exist?(railsrc)
26
+ extra_args = File.read(railsrc).split(/\n+/).flat_map(&:split)
27
+ puts "Using #{extra_args.join(" ")} from #{railsrc}"
28
+ plugin_args.insert(1, *extra_args)
29
+ end
30
+ end
31
+
32
+ run_plugin_generator plugin_args
33
+ end
34
+
35
+ private
36
+ def run_plugin_generator(plugin_args)
37
+ require "rails/generators"
38
+ require "rails/generators/rails/plugin/plugin_generator"
39
+ Rails::Generators::PluginGenerator.start plugin_args
40
+ end
41
+ end
42
+ end
43
+ end