Skip to content

Commit b5fc47c

Browse files
Make DatabaseTasks a module with real private methods
1 parent 30d8c39 commit b5fc47c

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module ActiveRecord
22
module Tasks # :nodoc:
3-
class DatabaseTasks # :nodoc:
3+
module DatabaseTasks # :nodoc:
4+
extend self
45

56
TASKS_PATTERNS = {
67
/mysql/ => ActiveRecord::Tasks::MySQLDatabaseTasks,
@@ -9,55 +10,55 @@ class DatabaseTasks # :nodoc:
910
}
1011
LOCAL_HOSTS = ['127.0.0.1', 'localhost']
1112

12-
def self.create(*arguments)
13+
def create(*arguments)
1314
configuration = arguments.first
1415
class_for_adapter(configuration['adapter']).new(*arguments).create
1516
rescue Exception => error
1617
$stderr.puts error, *(error.backtrace)
1718
$stderr.puts "Couldn't create database for #{configuration.inspect}"
1819
end
1920

20-
def self.create_all
21+
def create_all
2122
each_local_configuration { |configuration| create configuration }
2223
end
2324

24-
def self.create_current(environment = Rails.env)
25+
def create_current(environment = Rails.env)
2526
each_current_configuration(environment) { |configuration|
2627
create configuration
2728
}
2829
ActiveRecord::Base.establish_connection environment
2930
end
3031

31-
def self.drop(*arguments)
32+
def drop(*arguments)
3233
configuration = arguments.first
3334
class_for_adapter(configuration['adapter']).new(*arguments).drop
3435
rescue Exception => error
3536
$stderr.puts error, *(error.backtrace)
3637
$stderr.puts "Couldn't drop #{configuration['database']}"
3738
end
3839

39-
def self.drop_all
40+
def drop_all
4041
each_local_configuration { |configuration| drop configuration }
4142
end
4243

43-
def self.drop_current(environment = Rails.env)
44+
def drop_current(environment = Rails.env)
4445
each_current_configuration(environment) { |configuration|
4546
drop configuration
4647
}
4748
end
4849

49-
def self.purge(configuration)
50+
def purge(configuration)
5051
class_for_adapter(configuration['adapter']).new(configuration).purge
5152
end
5253

5354
private
5455

55-
def self.class_for_adapter(adapter)
56+
def class_for_adapter(adapter)
5657
key = TASKS_PATTERNS.keys.detect { |pattern| adapter[pattern] }
5758
TASKS_PATTERNS[key]
5859
end
5960

60-
def self.each_current_configuration(environment)
61+
def each_current_configuration(environment)
6162
environments = [environment]
6263
environments << 'test' if environment.development?
6364

@@ -67,7 +68,7 @@ def self.each_current_configuration(environment)
6768
end
6869
end
6970

70-
def self.each_local_configuration
71+
def each_local_configuration
7172
ActiveRecord::Base.configurations.each_value do |configuration|
7273
next unless configuration['database']
7374

@@ -79,9 +80,9 @@ def self.each_local_configuration
7980
end
8081
end
8182

82-
def self.local_database?(configuration)
83+
def local_database?(configuration)
8384
configuration['host'].in?(LOCAL_HOSTS) || configuration['host'].blank?
8485
end
8586
end
8687
end
87-
end
88+
end

0 commit comments

Comments
 (0)