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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +77 -567
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.rdoc +3 -3
- data/README.rdoc +1 -1
- data/exe/rails +2 -2
- data/lib/rails.rb +18 -18
- data/lib/rails/all.rb +1 -1
- data/lib/rails/api/generator.rb +28 -0
- data/lib/rails/api/task.rb +54 -42
- data/lib/rails/app_loader.rb +9 -9
- data/lib/rails/application.rb +30 -35
- data/lib/rails/application/bootstrap.rb +13 -7
- data/lib/rails/application/configuration.rb +30 -53
- data/lib/rails/application/default_middleware_stack.rb +3 -5
- data/lib/rails/application/finisher.rb +16 -7
- data/lib/rails/application/routes_reloader.rb +16 -1
- data/lib/rails/application_controller.rb +10 -10
- data/lib/rails/backtrace_cleaner.rb +5 -5
- data/lib/rails/cli.rb +7 -5
- data/lib/rails/code_statistics.rb +16 -17
- data/lib/rails/code_statistics_calculator.rb +3 -3
- data/lib/rails/command.rb +111 -0
- data/lib/rails/command/actions.rb +42 -0
- data/lib/rails/command/base.rb +149 -0
- data/lib/rails/command/behavior.rb +123 -0
- data/lib/rails/command/environment_argument.rb +34 -0
- data/lib/rails/commands.rb +2 -4
- data/lib/rails/commands/application/application_command.rb +29 -0
- data/lib/rails/commands/console/console_command.rb +89 -0
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +155 -0
- data/lib/rails/commands/destroy/destroy_command.rb +21 -0
- data/lib/rails/commands/generate/generate_command.rb +23 -0
- data/lib/rails/commands/help/USAGE +15 -0
- data/lib/rails/commands/help/help_command.rb +13 -0
- data/lib/rails/commands/new/new_command.rb +15 -0
- data/lib/rails/commands/plugin/plugin_command.rb +43 -0
- data/lib/rails/commands/rake/rake_command.rb +49 -0
- data/lib/rails/commands/runner/USAGE +17 -0
- data/lib/rails/commands/runner/runner_command.rb +46 -0
- data/lib/rails/commands/secrets/USAGE +52 -0
- data/lib/rails/commands/secrets/secrets_command.rb +36 -0
- data/lib/rails/commands/server/server_command.rb +177 -0
- data/lib/rails/commands/test/test_command.rb +20 -0
- data/lib/rails/commands/version/version_command.rb +9 -0
- data/lib/rails/configuration.rb +7 -7
- data/lib/rails/console/app.rb +4 -4
- data/lib/rails/dev_caching.rb +8 -8
- data/lib/rails/engine.rb +62 -63
- data/lib/rails/engine/commands.rb +6 -13
- data/lib/rails/engine/configuration.rb +2 -2
- data/lib/rails/gem_version.rb +3 -3
- data/lib/rails/generators.rb +229 -313
- data/lib/rails/generators/actions.rb +20 -21
- data/lib/rails/generators/actions/create_migration.rb +24 -25
- data/lib/rails/generators/active_model.rb +3 -3
- data/lib/rails/generators/app_base.rb +123 -93
- data/lib/rails/generators/base.rb +32 -33
- data/lib/rails/generators/css/assets/assets_generator.rb +1 -1
- data/lib/rails/generators/erb.rb +14 -14
- data/lib/rails/generators/erb/controller/controller_generator.rb +1 -1
- data/lib/rails/generators/erb/mailer/mailer_generator.rb +12 -12
- data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +3 -3
- data/lib/rails/generators/generated_attribute.rb +27 -27
- data/lib/rails/generators/js/assets/assets_generator.rb +1 -1
- data/lib/rails/generators/migration.rb +8 -8
- data/lib/rails/generators/model_helpers.rb +2 -2
- data/lib/rails/generators/named_base.rb +56 -56
- data/lib/rails/generators/rails/app/app_generator.rb +98 -81
- data/lib/rails/generators/rails/app/templates/Gemfile +7 -2
- data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -2
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +6 -4
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.js +1 -1
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +2 -2
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/bin/{setup → setup.tt} +6 -0
- data/lib/rails/generators/rails/app/templates/bin/{update → update.tt} +2 -1
- data/lib/rails/generators/rails/app/templates/bin/yarn +9 -0
- data/lib/rails/generators/rails/app/templates/config/cable.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +2 -1
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +10 -1
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb +4 -6
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +8 -3
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults.rb.tt +6 -5
- data/lib/rails/generators/rails/app/templates/config/locales/en.yml +10 -0
- data/lib/rails/generators/rails/app/templates/config/puma.rb +16 -7
- data/lib/rails/generators/rails/app/templates/config/secrets.yml +12 -2
- data/lib/rails/generators/rails/app/templates/gitignore +5 -1
- data/lib/rails/generators/rails/app/templates/package.json +5 -0
- data/lib/rails/generators/rails/app/templates/public/404.html +6 -6
- data/lib/rails/generators/rails/app/templates/public/422.html +6 -6
- data/lib/rails/generators/rails/app/templates/public/500.html +6 -6
- data/lib/rails/generators/rails/app/templates/public/robots.txt +0 -4
- data/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb +5 -0
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb +0 -1
- data/lib/rails/generators/rails/assets/assets_generator.rb +10 -10
- data/lib/rails/generators/rails/controller/controller_generator.rb +15 -12
- data/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb +66 -0
- data/lib/rails/generators/rails/encrypted_secrets/templates/config/secrets.yml.enc +3 -0
- data/lib/rails/generators/rails/generator/generator_generator.rb +2 -3
- data/lib/rails/generators/rails/helper/helper_generator.rb +1 -1
- data/lib/rails/generators/rails/model/model_generator.rb +1 -1
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +21 -26
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +1 -0
- data/lib/rails/generators/rails/plugin/templates/bin/test.tt +3 -9
- data/lib/rails/generators/rails/plugin/templates/test/application_system_test_case.rb +5 -0
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb +0 -3
- data/lib/rails/generators/rails/resource/resource_generator.rb +2 -2
- data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +5 -1
- data/lib/rails/generators/rails/scaffold/templates/scaffold.css +4 -8
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +2 -3
- data/lib/rails/generators/rails/system_test/USAGE +10 -0
- data/lib/rails/generators/rails/system_test/system_test_generator.rb +7 -0
- data/lib/rails/generators/rails/task/task_generator.rb +1 -2
- data/lib/rails/generators/resource_helpers.rb +13 -10
- data/lib/rails/generators/test_case.rb +5 -6
- data/lib/rails/generators/test_unit.rb +1 -1
- data/lib/rails/generators/test_unit/controller/controller_generator.rb +3 -3
- data/lib/rails/generators/test_unit/generator/generator_generator.rb +3 -3
- data/lib/rails/generators/test_unit/helper/helper_generator.rb +1 -1
- data/lib/rails/generators/test_unit/integration/integration_generator.rb +2 -2
- data/lib/rails/generators/test_unit/job/job_generator.rb +3 -3
- data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +5 -5
- data/lib/rails/generators/test_unit/model/model_generator.rb +3 -4
- data/lib/rails/generators/test_unit/plugin/plugin_generator.rb +2 -2
- data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +3 -3
- data/lib/rails/generators/test_unit/system/system_generator.rb +17 -0
- data/lib/rails/generators/test_unit/system/templates/application_system_test_case.rb +5 -0
- data/lib/rails/generators/test_unit/system/templates/system_test.rb +9 -0
- data/lib/rails/generators/testing/assertions.rb +4 -4
- data/lib/rails/generators/testing/behaviour.rb +20 -21
- data/lib/rails/info.rb +20 -20
- data/lib/rails/info_controller.rb +15 -15
- data/lib/rails/initializable.rb +6 -2
- data/lib/rails/mailers_controller.rb +11 -11
- data/lib/rails/paths.rb +4 -5
- data/lib/rails/plugin/test.rb +7 -0
- data/lib/rails/rack/logger.rb +44 -46
- data/lib/rails/railtie.rb +41 -38
- data/lib/rails/railtie/configurable.rb +6 -6
- data/lib/rails/railtie/configuration.rb +1 -1
- data/lib/rails/ruby_version_check.rb +1 -1
- data/lib/rails/secrets.rb +111 -0
- data/lib/rails/source_annotation_extractor.rb +15 -9
- data/lib/rails/tasks.rb +3 -2
- data/lib/rails/tasks/annotations.rake +3 -3
- data/lib/rails/tasks/dev.rake +2 -2
- data/lib/rails/tasks/engine.rake +4 -4
- data/lib/rails/tasks/framework.rake +4 -18
- data/lib/rails/tasks/initializers.rake +1 -1
- data/lib/rails/tasks/log.rake +14 -10
- data/lib/rails/tasks/middleware.rake +1 -1
- data/lib/rails/tasks/misc.rake +10 -10
- data/lib/rails/tasks/restart.rake +4 -4
- data/lib/rails/tasks/routes.rake +3 -12
- data/lib/rails/tasks/statistics.rake +3 -3
- data/lib/rails/tasks/tmp.rake +7 -7
- data/lib/rails/tasks/yarn.rake +11 -0
- data/lib/rails/templates/rails/mailers/email.html.erb +4 -1
- data/lib/rails/test_help.rb +28 -10
- data/lib/rails/test_unit/line_filtering.rb +69 -3
- data/lib/rails/test_unit/minitest_plugin.rb +139 -0
- data/lib/rails/test_unit/railtie.rb +2 -1
- data/lib/rails/test_unit/reporter.rb +3 -8
- data/lib/rails/test_unit/test_requirer.rb +28 -0
- data/lib/rails/test_unit/testing.rake +19 -14
- data/lib/rails/version.rb +1 -1
- data/lib/rails/welcome_controller.rb +1 -1
- metadata +53 -30
- data/lib/minitest/rails_plugin.rb +0 -49
- data/lib/rails/commands/application.rb +0 -17
- data/lib/rails/commands/commands_tasks.rb +0 -180
- data/lib/rails/commands/console.rb +0 -68
- data/lib/rails/commands/console_helper.rb +0 -34
- data/lib/rails/commands/dbconsole.rb +0 -173
- data/lib/rails/commands/destroy.rb +0 -11
- data/lib/rails/commands/generate.rb +0 -13
- data/lib/rails/commands/plugin.rb +0 -23
- data/lib/rails/commands/rake_proxy.rb +0 -41
- data/lib/rails/commands/runner.rb +0 -71
- data/lib/rails/commands/server.rb +0 -163
- data/lib/rails/commands/test.rb +0 -10
- data/lib/rails/engine/commands_tasks.rb +0 -118
- data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +0 -3
- data/lib/rails/rack/debugger.rb +0 -3
- data/lib/rails/test_unit/runner.rb +0 -141
@@ -1,17 +0,0 @@
|
|
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
|
-
end
|
15
|
-
|
16
|
-
args = Rails::Generators::ARGVScrubber.new(ARGV).prepare!
|
17
|
-
Rails::Generators::AppGenerator.start args
|
@@ -1,180 +0,0 @@
|
|
1
|
-
require 'rails/commands/rake_proxy'
|
2
|
-
|
3
|
-
module Rails
|
4
|
-
# This is a class which takes in a rails command and initiates the appropriate
|
5
|
-
# initiation sequence.
|
6
|
-
#
|
7
|
-
# Warning: This class mutates ARGV because some commands require manipulating
|
8
|
-
# it before they are run.
|
9
|
-
class CommandsTasks # :nodoc:
|
10
|
-
include Rails::RakeProxy
|
11
|
-
|
12
|
-
attr_reader :argv
|
13
|
-
|
14
|
-
HELP_MESSAGE = <<-EOT
|
15
|
-
Usage: rails COMMAND [ARGS]
|
16
|
-
|
17
|
-
The most common rails commands are:
|
18
|
-
generate Generate new code (short-cut alias: "g")
|
19
|
-
console Start the Rails console (short-cut alias: "c")
|
20
|
-
server Start the Rails server (short-cut alias: "s")
|
21
|
-
test Run tests (short-cut alias: "t")
|
22
|
-
dbconsole Start a console for the database specified in config/database.yml
|
23
|
-
(short-cut alias: "db")
|
24
|
-
new Create a new Rails application. "rails new my_app" creates a
|
25
|
-
new application called MyApp in "./my_app"
|
26
|
-
|
27
|
-
All commands can be run with -h (or --help) for more information.
|
28
|
-
|
29
|
-
In addition to those commands, there are:
|
30
|
-
EOT
|
31
|
-
|
32
|
-
ADDITIONAL_COMMANDS = [
|
33
|
-
[ 'destroy', 'Undo code generated with "generate" (short-cut alias: "d")' ],
|
34
|
-
[ 'plugin new', 'Generates skeleton for developing a Rails plugin' ],
|
35
|
-
[ 'runner',
|
36
|
-
'Run a piece of code in the application environment (short-cut alias: "r")' ]
|
37
|
-
]
|
38
|
-
|
39
|
-
COMMAND_WHITELIST = %w(plugin generate destroy console server dbconsole runner new version help test)
|
40
|
-
|
41
|
-
def initialize(argv)
|
42
|
-
@argv = argv
|
43
|
-
end
|
44
|
-
|
45
|
-
def run_command!(command)
|
46
|
-
command = parse_command(command)
|
47
|
-
|
48
|
-
if COMMAND_WHITELIST.include?(command)
|
49
|
-
send(command)
|
50
|
-
else
|
51
|
-
run_rake_task(command)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def plugin
|
56
|
-
require_command!("plugin")
|
57
|
-
end
|
58
|
-
|
59
|
-
def generate
|
60
|
-
generate_or_destroy(:generate)
|
61
|
-
end
|
62
|
-
|
63
|
-
def destroy
|
64
|
-
generate_or_destroy(:destroy)
|
65
|
-
end
|
66
|
-
|
67
|
-
def console
|
68
|
-
require_command!("console")
|
69
|
-
options = Rails::Console.parse_arguments(argv)
|
70
|
-
|
71
|
-
# RAILS_ENV needs to be set before config/application is required
|
72
|
-
ENV['RAILS_ENV'] = options[:environment] if options[:environment]
|
73
|
-
|
74
|
-
# shift ARGV so IRB doesn't freak
|
75
|
-
shift_argv!
|
76
|
-
|
77
|
-
require_application_and_environment!
|
78
|
-
Rails::Console.start(Rails.application, options)
|
79
|
-
end
|
80
|
-
|
81
|
-
def server
|
82
|
-
set_application_directory!
|
83
|
-
require_command!("server")
|
84
|
-
|
85
|
-
Rails::Server.new.tap do |server|
|
86
|
-
# We need to require application after the server sets environment,
|
87
|
-
# otherwise the --environment option given to the server won't propagate.
|
88
|
-
require APP_PATH
|
89
|
-
Dir.chdir(Rails.application.root)
|
90
|
-
server.start
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def test
|
95
|
-
require_command!("test")
|
96
|
-
end
|
97
|
-
|
98
|
-
def dbconsole
|
99
|
-
require_command!("dbconsole")
|
100
|
-
Rails::DBConsole.start
|
101
|
-
end
|
102
|
-
|
103
|
-
def runner
|
104
|
-
require_command!("runner")
|
105
|
-
end
|
106
|
-
|
107
|
-
def new
|
108
|
-
if %w(-h --help).include?(argv.first)
|
109
|
-
require_command!("application")
|
110
|
-
else
|
111
|
-
exit_with_initialization_warning!
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
def version
|
116
|
-
argv.unshift '--version'
|
117
|
-
require_command!("application")
|
118
|
-
end
|
119
|
-
|
120
|
-
def help
|
121
|
-
write_help_message
|
122
|
-
write_commands ADDITIONAL_COMMANDS + formatted_rake_tasks
|
123
|
-
end
|
124
|
-
|
125
|
-
private
|
126
|
-
|
127
|
-
def exit_with_initialization_warning!
|
128
|
-
puts "Can't initialize a new Rails application within the directory of another, please change to a non-Rails directory first.\n"
|
129
|
-
puts "Type 'rails' for help."
|
130
|
-
exit(1)
|
131
|
-
end
|
132
|
-
|
133
|
-
def shift_argv!
|
134
|
-
argv.shift if argv.first && argv.first[0] != '-'
|
135
|
-
end
|
136
|
-
|
137
|
-
def require_command!(command)
|
138
|
-
require "rails/commands/#{command}"
|
139
|
-
end
|
140
|
-
|
141
|
-
def generate_or_destroy(command)
|
142
|
-
require 'rails/generators'
|
143
|
-
require_application_and_environment!
|
144
|
-
Rails.application.load_generators
|
145
|
-
require_command!(command)
|
146
|
-
end
|
147
|
-
|
148
|
-
# Change to the application's path if there is no config.ru file in current directory.
|
149
|
-
# This allows us to run `rails server` from other directories, but still get
|
150
|
-
# the main config.ru and properly set the tmp directory.
|
151
|
-
def set_application_directory!
|
152
|
-
Dir.chdir(File.expand_path('../../', APP_PATH)) unless File.exist?(File.expand_path("config.ru"))
|
153
|
-
end
|
154
|
-
|
155
|
-
def require_application_and_environment!
|
156
|
-
require APP_PATH
|
157
|
-
Rails.application.require_environment!
|
158
|
-
end
|
159
|
-
|
160
|
-
def write_help_message
|
161
|
-
puts HELP_MESSAGE
|
162
|
-
end
|
163
|
-
|
164
|
-
def write_commands(commands)
|
165
|
-
width = commands.map { |name, _| name.size }.max || 10
|
166
|
-
commands.each { |command| printf(" %-#{width}s %s\n", *command) }
|
167
|
-
end
|
168
|
-
|
169
|
-
def parse_command(command)
|
170
|
-
case command
|
171
|
-
when '--version', '-v'
|
172
|
-
'version'
|
173
|
-
when '--help', '-h'
|
174
|
-
'help'
|
175
|
-
else
|
176
|
-
command
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'optparse'
|
2
|
-
require 'irb'
|
3
|
-
require 'irb/completion'
|
4
|
-
require 'rails/commands/console_helper'
|
5
|
-
|
6
|
-
module Rails
|
7
|
-
class Console
|
8
|
-
include ConsoleHelper
|
9
|
-
|
10
|
-
class << self
|
11
|
-
def parse_arguments(arguments)
|
12
|
-
options = {}
|
13
|
-
|
14
|
-
OptionParser.new do |opt|
|
15
|
-
opt.banner = "Usage: rails console [environment] [options]"
|
16
|
-
opt.on('-s', '--sandbox', 'Rollback database modifications on exit.') { |v| options[:sandbox] = v }
|
17
|
-
opt.on("-e", "--environment=name", String,
|
18
|
-
"Specifies the environment to run this console under (test/development/production).",
|
19
|
-
"Default: development") { |v| options[:environment] = v.strip }
|
20
|
-
opt.parse!(arguments)
|
21
|
-
end
|
22
|
-
|
23
|
-
set_options_env(arguments, options)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
attr_reader :options, :app, :console
|
28
|
-
|
29
|
-
def initialize(app, options={})
|
30
|
-
@app = app
|
31
|
-
@options = options
|
32
|
-
|
33
|
-
app.sandbox = sandbox?
|
34
|
-
app.load_console
|
35
|
-
|
36
|
-
@console = app.config.console || IRB
|
37
|
-
end
|
38
|
-
|
39
|
-
def sandbox?
|
40
|
-
options[:sandbox]
|
41
|
-
end
|
42
|
-
|
43
|
-
def environment
|
44
|
-
options[:environment] ||= super
|
45
|
-
end
|
46
|
-
alias_method :environment?, :environment
|
47
|
-
|
48
|
-
def set_environment!
|
49
|
-
Rails.env = environment
|
50
|
-
end
|
51
|
-
|
52
|
-
def start
|
53
|
-
set_environment! if environment?
|
54
|
-
|
55
|
-
if sandbox?
|
56
|
-
puts "Loading #{Rails.env} environment in sandbox (Rails #{Rails.version})"
|
57
|
-
puts "Any modifications you make will be rolled back on exit"
|
58
|
-
else
|
59
|
-
puts "Loading #{Rails.env} environment (Rails #{Rails.version})"
|
60
|
-
end
|
61
|
-
|
62
|
-
if defined?(console::ExtendCommandBundle)
|
63
|
-
console::ExtendCommandBundle.include(Rails::ConsoleMethods)
|
64
|
-
end
|
65
|
-
console.start
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'active_support/concern'
|
2
|
-
|
3
|
-
module Rails
|
4
|
-
module ConsoleHelper # :nodoc:
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
module ClassMethods
|
8
|
-
def start(*args)
|
9
|
-
new(*args).start
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
def set_options_env(arguments, options)
|
14
|
-
if arguments.first && arguments.first[0] != '-'
|
15
|
-
env = arguments.first
|
16
|
-
if available_environments.include? env
|
17
|
-
options[:environment] = env
|
18
|
-
else
|
19
|
-
options[:environment] = %w(production development test).detect { |e| e =~ /^#{env}/ } || env
|
20
|
-
end
|
21
|
-
end
|
22
|
-
options
|
23
|
-
end
|
24
|
-
|
25
|
-
def available_environments
|
26
|
-
Dir['config/environments/*.rb'].map { |fname| File.basename(fname, '.*') }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def environment
|
31
|
-
ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,173 +0,0 @@
|
|
1
|
-
require 'erb'
|
2
|
-
require 'yaml'
|
3
|
-
require 'optparse'
|
4
|
-
require 'rails/commands/console_helper'
|
5
|
-
|
6
|
-
module Rails
|
7
|
-
class DBConsole
|
8
|
-
include ConsoleHelper
|
9
|
-
|
10
|
-
attr_reader :arguments
|
11
|
-
|
12
|
-
class << self
|
13
|
-
def parse_arguments(arguments)
|
14
|
-
options = {}
|
15
|
-
|
16
|
-
OptionParser.new do |opt|
|
17
|
-
opt.banner = "Usage: rails dbconsole [environment] [options]"
|
18
|
-
opt.on("-p", "--include-password", "Automatically provide the password from database.yml") do |v|
|
19
|
-
options['include_password'] = true
|
20
|
-
end
|
21
|
-
|
22
|
-
opt.on("--mode [MODE]", ['html', 'list', 'line', 'column'],
|
23
|
-
"Automatically put the sqlite3 database in the specified mode (html, list, line, column).") do |mode|
|
24
|
-
options['mode'] = mode
|
25
|
-
end
|
26
|
-
|
27
|
-
opt.on("--header") do |h|
|
28
|
-
options['header'] = h
|
29
|
-
end
|
30
|
-
|
31
|
-
opt.on("-h", "--help", "Show this help message.") do
|
32
|
-
puts opt
|
33
|
-
exit
|
34
|
-
end
|
35
|
-
|
36
|
-
opt.on("-e", "--environment=name", String,
|
37
|
-
"Specifies the environment to run this console under (test/development/production).",
|
38
|
-
"Default: development"
|
39
|
-
) { |v| options[:environment] = v.strip }
|
40
|
-
|
41
|
-
opt.parse!(arguments)
|
42
|
-
abort opt.to_s unless (0..1).include?(arguments.size)
|
43
|
-
end
|
44
|
-
|
45
|
-
set_options_env(arguments, options)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def initialize(arguments = ARGV)
|
50
|
-
@arguments = arguments
|
51
|
-
end
|
52
|
-
|
53
|
-
def start
|
54
|
-
options = self.class.parse_arguments(arguments)
|
55
|
-
ENV['RAILS_ENV'] = options[:environment] || environment
|
56
|
-
|
57
|
-
case config["adapter"]
|
58
|
-
when /^(jdbc)?mysql/
|
59
|
-
args = {
|
60
|
-
'host' => '--host',
|
61
|
-
'port' => '--port',
|
62
|
-
'socket' => '--socket',
|
63
|
-
'username' => '--user',
|
64
|
-
'encoding' => '--default-character-set',
|
65
|
-
'sslca' => '--ssl-ca',
|
66
|
-
'sslcert' => '--ssl-cert',
|
67
|
-
'sslcapath' => '--ssl-capath',
|
68
|
-
'sslcipher' => '--ssl-cipher',
|
69
|
-
'sslkey' => '--ssl-key'
|
70
|
-
}.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact
|
71
|
-
|
72
|
-
if config['password'] && options['include_password']
|
73
|
-
args << "--password=#{config['password']}"
|
74
|
-
elsif config['password'] && !config['password'].to_s.empty?
|
75
|
-
args << "-p"
|
76
|
-
end
|
77
|
-
|
78
|
-
args << config['database']
|
79
|
-
|
80
|
-
find_cmd_and_exec(['mysql', 'mysql5'], *args)
|
81
|
-
|
82
|
-
when /^postgres|^postgis/
|
83
|
-
ENV['PGUSER'] = config["username"] if config["username"]
|
84
|
-
ENV['PGHOST'] = config["host"] if config["host"]
|
85
|
-
ENV['PGPORT'] = config["port"].to_s if config["port"]
|
86
|
-
ENV['PGPASSWORD'] = config["password"].to_s if config["password"] && options['include_password']
|
87
|
-
find_cmd_and_exec('psql', config["database"])
|
88
|
-
|
89
|
-
when "sqlite3"
|
90
|
-
args = []
|
91
|
-
|
92
|
-
args << "-#{options['mode']}" if options['mode']
|
93
|
-
args << "-header" if options['header']
|
94
|
-
args << File.expand_path(config['database'], Rails.respond_to?(:root) ? Rails.root : nil)
|
95
|
-
|
96
|
-
find_cmd_and_exec('sqlite3', *args)
|
97
|
-
|
98
|
-
when "oracle", "oracle_enhanced"
|
99
|
-
logon = ""
|
100
|
-
|
101
|
-
if config['username']
|
102
|
-
logon = config['username']
|
103
|
-
logon << "/#{config['password']}" if config['password'] && options['include_password']
|
104
|
-
logon << "@#{config['database']}" if config['database']
|
105
|
-
end
|
106
|
-
|
107
|
-
find_cmd_and_exec('sqlplus', logon)
|
108
|
-
|
109
|
-
when "sqlserver"
|
110
|
-
args = []
|
111
|
-
|
112
|
-
args += ["-D", "#{config['database']}"] if config['database']
|
113
|
-
args += ["-U", "#{config['username']}"] if config['username']
|
114
|
-
args += ["-P", "#{config['password']}"] if config['password']
|
115
|
-
|
116
|
-
if config['host']
|
117
|
-
host_arg = "#{config['host']}"
|
118
|
-
host_arg << ":#{config['port']}" if config['port']
|
119
|
-
args += ["-S", host_arg]
|
120
|
-
end
|
121
|
-
|
122
|
-
find_cmd_and_exec("sqsh", *args)
|
123
|
-
|
124
|
-
else
|
125
|
-
abort "Unknown command-line client for #{config['database']}."
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
def config
|
130
|
-
@config ||= begin
|
131
|
-
if configurations[environment].blank?
|
132
|
-
raise ActiveRecord::AdapterNotSpecified, "'#{environment}' database is not configured. Available configuration: #{configurations.inspect}"
|
133
|
-
else
|
134
|
-
configurations[environment]
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
def environment
|
140
|
-
Rails.respond_to?(:env) ? Rails.env : super
|
141
|
-
end
|
142
|
-
|
143
|
-
protected
|
144
|
-
def configurations
|
145
|
-
require APP_PATH
|
146
|
-
ActiveRecord::Base.configurations = Rails.application.config.database_configuration
|
147
|
-
ActiveRecord::Base.configurations
|
148
|
-
end
|
149
|
-
|
150
|
-
def find_cmd_and_exec(commands, *args)
|
151
|
-
commands = Array(commands)
|
152
|
-
|
153
|
-
dirs_on_path = ENV['PATH'].to_s.split(File::PATH_SEPARATOR)
|
154
|
-
unless (ext = RbConfig::CONFIG['EXEEXT']).empty?
|
155
|
-
commands = commands.map{|cmd| "#{cmd}#{ext}"}
|
156
|
-
end
|
157
|
-
|
158
|
-
full_path_command = nil
|
159
|
-
found = commands.detect do |cmd|
|
160
|
-
dirs_on_path.detect do |path|
|
161
|
-
full_path_command = File.join(path, cmd)
|
162
|
-
File.file?(full_path_command) && File.executable?(full_path_command)
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
if found
|
167
|
-
exec full_path_command, *args
|
168
|
-
else
|
169
|
-
abort("Couldn't find database client: #{commands.join(', ')}. Check your $PATH and try again.")
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|