Skip to content

Commit 1c77aa0

Browse files
cleanup Rakefile
1 parent b580d14 commit 1c77aa0

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

Rakefile

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,57 @@
1-
require "bundler/gem_tasks"
2-
require "yaml"
3-
require "active_record"
1+
require 'bundler/gem_tasks'
2+
require 'yaml'
3+
require 'active_record'
44

55
namespace :test do
66
task :all do
7-
Dir.glob("./gemfiles/Gemfile*").each do |gemfile|
8-
next if gemfile.end_with?(".lock")
7+
Dir.glob('./gemfiles/Gemfile*').each do |gemfile|
8+
next if gemfile.end_with?('.lock')
9+
910
puts "Running specs for #{Pathname.new(gemfile).basename}"
1011
system("BUNDLE_GEMFILE=#{gemfile} bundle install > /dev/null && BUNDLE_GEMFILE=#{gemfile} bundle exec rspec")
11-
puts ""
12+
puts ''
1213
end
1314
end
1415
end
1516

1617
namespace :db do
17-
database_config = YAML.load(File.open("./spec/support/database.yml"))
18-
migration_path = File.expand_path("./spec/support/migrations")
18+
database_config = YAML.load(File.open('./spec/support/database.yml'))
19+
migration_path = File.expand_path('./spec/support/migrations')
1920

20-
desc "Create the database"
21+
desc 'Create the database'
2122
task :create do
2223
if database_config[:adapter] == 'sqlite3'
2324
# For SQLite3, just ensure the directory exists
2425
db_file = database_config.fetch(:database)
2526
FileUtils.mkdir_p(File.dirname(db_file)) unless File.dirname(db_file) == '.'
26-
puts "Database created (SQLite3 will create file on first connection)."
27+
puts 'Database created (SQLite3 will create file on first connection).'
2728
else
2829
# For other databases (MySQL, PostgreSQL, etc.)
2930
admin_config = database_config.merge(database: "mysql")
3031
ActiveRecord::Base.establish_connection(admin_config)
3132
ActiveRecord::Base.connection.create_database(database_config.fetch(:database))
32-
puts "Database created."
33+
puts 'Database created.'
3334
end
3435
end
3536

36-
desc "Migrate the database"
37+
desc 'Migrate the database'
3738
task :migrate do
3839
ActiveRecord::Base.establish_connection(database_config)
39-
40+
4041
# Handle different Rails versions
4142
active_record_version = Gem::Version.new(ActiveRecord::VERSION::STRING)
42-
43+
4344
if active_record_version >= Gem::Version.new("6.0")
4445
ActiveRecord::MigrationContext.new(migration_path).migrate
4546
else
4647
ActiveRecord::Migrator.migrate(migration_path)
4748
end
48-
49-
Rake::Task["db:schema"].invoke
50-
puts "Database migrated."
49+
50+
Rake::Task['db:schema'].invoke
51+
puts 'Database migrated.'
5152
end
5253

53-
desc "Drop the database"
54+
desc 'Drop the database'
5455
task :drop do
5556
if database_config[:adapter] == 'sqlite3'
5657
# For SQLite3, just delete the file
@@ -62,10 +63,10 @@ namespace :db do
6263
ActiveRecord::Base.establish_connection(admin_config)
6364
ActiveRecord::Base.connection.drop_database(database_config.fetch(:database))
6465
end
65-
puts "Database deleted."
66+
puts 'Database deleted.'
6667
end
6768

68-
desc "Reset the database"
69+
desc 'Reset the database'
6970
task reset: [:drop, :create, :migrate]
7071
desc 'Create a db/schema.rb file that is portable against any DB supported by AR'
7172

0 commit comments

Comments
 (0)