1
1
module ActiveRecord
2
2
module Tasks # :nodoc:
3
- class DatabaseTasks # :nodoc:
3
+ module DatabaseTasks # :nodoc:
4
+ extend self
4
5
5
6
TASKS_PATTERNS = {
6
7
/mysql/ => ActiveRecord ::Tasks ::MySQLDatabaseTasks ,
@@ -9,55 +10,55 @@ class DatabaseTasks # :nodoc:
9
10
}
10
11
LOCAL_HOSTS = [ '127.0.0.1' , 'localhost' ]
11
12
12
- def self . create ( *arguments )
13
+ def create ( *arguments )
13
14
configuration = arguments . first
14
15
class_for_adapter ( configuration [ 'adapter' ] ) . new ( *arguments ) . create
15
16
rescue Exception => error
16
17
$stderr. puts error , *( error . backtrace )
17
18
$stderr. puts "Couldn't create database for #{ configuration . inspect } "
18
19
end
19
20
20
- def self . create_all
21
+ def create_all
21
22
each_local_configuration { |configuration | create configuration }
22
23
end
23
24
24
- def self . create_current ( environment = Rails . env )
25
+ def create_current ( environment = Rails . env )
25
26
each_current_configuration ( environment ) { |configuration |
26
27
create configuration
27
28
}
28
29
ActiveRecord ::Base . establish_connection environment
29
30
end
30
31
31
- def self . drop ( *arguments )
32
+ def drop ( *arguments )
32
33
configuration = arguments . first
33
34
class_for_adapter ( configuration [ 'adapter' ] ) . new ( *arguments ) . drop
34
35
rescue Exception => error
35
36
$stderr. puts error , *( error . backtrace )
36
37
$stderr. puts "Couldn't drop #{ configuration [ 'database' ] } "
37
38
end
38
39
39
- def self . drop_all
40
+ def drop_all
40
41
each_local_configuration { |configuration | drop configuration }
41
42
end
42
43
43
- def self . drop_current ( environment = Rails . env )
44
+ def drop_current ( environment = Rails . env )
44
45
each_current_configuration ( environment ) { |configuration |
45
46
drop configuration
46
47
}
47
48
end
48
49
49
- def self . purge ( configuration )
50
+ def purge ( configuration )
50
51
class_for_adapter ( configuration [ 'adapter' ] ) . new ( configuration ) . purge
51
52
end
52
53
53
54
private
54
55
55
- def self . class_for_adapter ( adapter )
56
+ def class_for_adapter ( adapter )
56
57
key = TASKS_PATTERNS . keys . detect { |pattern | adapter [ pattern ] }
57
58
TASKS_PATTERNS [ key ]
58
59
end
59
60
60
- def self . each_current_configuration ( environment )
61
+ def each_current_configuration ( environment )
61
62
environments = [ environment ]
62
63
environments << 'test' if environment . development?
63
64
@@ -67,7 +68,7 @@ def self.each_current_configuration(environment)
67
68
end
68
69
end
69
70
70
- def self . each_local_configuration
71
+ def each_local_configuration
71
72
ActiveRecord ::Base . configurations . each_value do |configuration |
72
73
next unless configuration [ 'database' ]
73
74
@@ -79,9 +80,9 @@ def self.each_local_configuration
79
80
end
80
81
end
81
82
82
- def self . local_database? ( configuration )
83
+ def local_database? ( configuration )
83
84
configuration [ 'host' ] . in? ( LOCAL_HOSTS ) || configuration [ 'host' ] . blank?
84
85
end
85
86
end
86
87
end
87
- end
88
+ end
0 commit comments