Class: RebuildRailsAppDatabase
Overview
Rebuild the database for a rails application or a rails engine. This task honors the following command line options
--skip-db-prep Causes the task to be skipped
Instance Attribute Summary
#exit_status, #id, #name, #options, #quiet, #run_time, #runner, #successful
Class Method Summary
collapse
Instance Method Summary
collapse
name_for_class, register_option
default_quiet, default_stop_on_problem, #failed?, #helpers, #initialize, provide_options_to, #quiet?, #run, #stop_on_problem?, #verbose?
Class Method Details
.description ⇒ Object
4
5
6
|
# File 'lib/rspec_starter/tasks/rebuild_rails_app_database.rb', line 4
def self.description
"Rebuild a Ruby on Rails application or engine database."
end
|
.register_options ⇒ Object
8
9
10
11
12
13
14
|
# File 'lib/rspec_starter/tasks/rebuild_rails_app_database.rb', line 8
def self.register_options
register_option default: false, switch: '--skip-db-prep',
switch_description: "DO NOT prepare the Rails application database"
register_option name: "command",
default: "DISABLE_DATABASE_ENVIRONMENT_CHECK=1 RAILS_ENV=test rake db:drop db:create db:schema:load",
description: "A command string that is used to rebuild the database."
end
|
Instance Method Details
#execute ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/rspec_starter/tasks/rebuild_rails_app_database.rb', line 24
def execute
if quiet?
@stdout, @stderr, @status = Open3.capture3(options.command)
else
puts "\n\n"
@verbose_command_passed = system options.command
@status = $CHILD_STATUS
print @starting_message
end
problem if command_failed?
end
|
#should_skip? ⇒ Boolean
16
17
18
|
# File 'lib/rspec_starter/tasks/rebuild_rails_app_database.rb', line 16
def should_skip?
options.skip_db_prep || options.command.nil? || options.command.empty?
end
|
#starting_message ⇒ Object
20
21
22
|
# File 'lib/rspec_starter/tasks/rebuild_rails_app_database.rb', line 20
def starting_message
"Running #{options.command.highlight}"
end
|
#write_error_info ⇒ Object
36
37
38
39
40
41
|
# File 'lib/rspec_starter/tasks/rebuild_rails_app_database.rb', line 36
def write_error_info
puts @stdout
puts @stderr
puts "\n\nThere was an error rebuilding the test database. See the output above for details " \
"or manually run '#{options.command}' for more information.".colorize(:red)
end
|