guard-migrate 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/guard/migrate.rb +66 -18
- data/lib/guard/migrate/templates/Guardfile +1 -0
- data/lib/guard/migrate/version.rb +1 -1
- data/spec/guard/migrate_spec.rb +10 -0
- metadata +7 -7
data/lib/guard/migrate.rb
CHANGED
@@ -41,7 +41,7 @@ module Guard
|
|
41
41
|
# Called once when Guard starts
|
42
42
|
# Please override initialize method to init stuff
|
43
43
|
def start
|
44
|
-
|
44
|
+
migrate if run_on_start?
|
45
45
|
end
|
46
46
|
|
47
47
|
# Called on Ctrl-C signal (when Guard quits)
|
@@ -52,41 +52,89 @@ module Guard
|
|
52
52
|
# Called on Ctrl-Z signal
|
53
53
|
# This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
|
54
54
|
def reload
|
55
|
-
|
55
|
+
migrate if run_on_start?
|
56
56
|
end
|
57
57
|
|
58
58
|
# Called on Ctrl-/ signal
|
59
59
|
# This method should be principally used for long action like running all specs/tests/...
|
60
60
|
def run_all
|
61
|
-
|
61
|
+
migrate if run_on_start?
|
62
62
|
end
|
63
63
|
|
64
64
|
# Called on file(s) modifications
|
65
65
|
def run_on_changes(paths)
|
66
|
-
|
66
|
+
if paths.any?{|path| path.match(%r{^db/migrate/(\d+).+\.rb})}
|
67
|
+
migrate(paths.map{|path| path.scan(%r{^db/migrate/(\d+).+\.rb}).flatten.first})
|
68
|
+
elsif paths.any?{|path| path.match(%r{^db/seeds\.rb$})}
|
69
|
+
seed_only
|
70
|
+
end
|
67
71
|
end
|
68
72
|
|
69
73
|
def migrate(paths = [])
|
70
|
-
return if !
|
71
|
-
system
|
74
|
+
return if !reset? && paths.empty?
|
75
|
+
system rake_string if reset?
|
72
76
|
paths.each do |path|
|
73
|
-
UI.info "Running #{
|
74
|
-
system
|
77
|
+
UI.info "Running #{rake_string(path)}"
|
78
|
+
system rake_string(path)
|
75
79
|
end
|
76
80
|
end
|
77
81
|
|
82
|
+
def seed_only
|
83
|
+
UI.info "Running #{seed_only_string}"
|
84
|
+
system seed_only_string
|
85
|
+
end
|
86
|
+
|
87
|
+
def run_redo?(path)
|
88
|
+
!reset? && path && !path.empty?
|
89
|
+
end
|
90
|
+
|
78
91
|
def rake_string(path = nil)
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
92
|
+
[
|
93
|
+
rake_command,
|
94
|
+
migrate_string(path),
|
95
|
+
seed_string,
|
96
|
+
clone_string,
|
97
|
+
rails_env_string
|
98
|
+
].compact.join(" ")
|
99
|
+
end
|
100
|
+
|
101
|
+
def seed_only_string
|
102
|
+
[
|
103
|
+
rake_command,
|
104
|
+
seed_string,
|
105
|
+
clone_string,
|
106
|
+
rails_env_string
|
107
|
+
].compact.join(" ")
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
def rake_command
|
113
|
+
command = ""
|
114
|
+
command += "bundle exec " if bundler?
|
115
|
+
command += "rake"
|
116
|
+
command
|
89
117
|
end
|
118
|
+
|
119
|
+
def rails_env_string
|
120
|
+
"RAILS_ENV=#{rails_env}" if rails_env
|
121
|
+
end
|
122
|
+
|
123
|
+
def clone_string
|
124
|
+
"db:test:clone" if test_clone?
|
125
|
+
end
|
126
|
+
|
127
|
+
def seed_string
|
128
|
+
"db:seed" if @seed
|
129
|
+
end
|
130
|
+
|
131
|
+
def migrate_string(path)
|
132
|
+
string = "db:migrate"
|
133
|
+
string += ":reset" if reset?
|
134
|
+
string += ":redo VERSION=#{path}" if run_redo?(path)
|
135
|
+
string
|
136
|
+
end
|
137
|
+
|
90
138
|
end
|
91
139
|
end
|
92
140
|
|
data/spec/guard/migrate_spec.rb
CHANGED
@@ -142,6 +142,16 @@ describe Guard::Migrate do
|
|
142
142
|
end
|
143
143
|
end
|
144
144
|
end
|
145
|
+
|
146
|
+
context "when the seeds file is passed as the paths" do
|
147
|
+
let(:paths){ ['db/seeds.rb'] }
|
148
|
+
let(:options){ {:seed => true, :test_clone => true} }
|
149
|
+
its(:seed_only_string){ should match(/db:seed db:test:clone/) }
|
150
|
+
it "runs the rake command with seed only" do
|
151
|
+
subject.should_receive(:system).with(subject.seed_only_string)
|
152
|
+
subject.run_on_changes paths
|
153
|
+
end
|
154
|
+
end
|
145
155
|
end
|
146
156
|
|
147
157
|
context "run on change should fixup the path to only the version" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-migrate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: guard
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 2.
|
37
|
+
version: 2.11.0
|
38
38
|
type: :development
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 2.
|
45
|
+
version: 2.11.0
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: guard-rspec
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -50,7 +50,7 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: 1.2.0
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -58,7 +58,7 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 1.2.0
|
62
62
|
description: Guard::Migrate automatically runs your database migrations when needed
|
63
63
|
email:
|
64
64
|
- geofflanotte@gmail.com
|
@@ -91,7 +91,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
91
|
version: '0'
|
92
92
|
segments:
|
93
93
|
- 0
|
94
|
-
hash:
|
94
|
+
hash: 4308447101882295894
|
95
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
96
|
none: false
|
97
97
|
requirements:
|