box-release 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/box-release.gemspec +2 -2
- data/lib/box/release.rb +3 -0
- data/lib/box/release/base.rb +1 -1
- data/lib/box/release/cli.rb +17 -2
- data/lib/box/release/memory.rb +4 -0
- data/lib/box/release/version.rb +1 -1
- data/spec/box/release/base_spec.rb +13 -2
- data/spec/box/release/cli_spec.rb +31 -0
- metadata +32 -4
data/box-release.gemspec
CHANGED
data/lib/box/release.rb
CHANGED
data/lib/box/release/base.rb
CHANGED
data/lib/box/release/cli.rb
CHANGED
@@ -4,7 +4,7 @@ module Box
|
|
4
4
|
module Release
|
5
5
|
class CLI
|
6
6
|
|
7
|
-
attr_accessor :url, :current_definition, :install_command, :before_download_command
|
7
|
+
attr_accessor :url, :current_definition, :install_command, :before_download_command, :after_download_command, :download_directory
|
8
8
|
|
9
9
|
def initialize(arguments = [])
|
10
10
|
@install_command = "/usr/local/sbin/box-upgrade"
|
@@ -32,6 +32,10 @@ module Box
|
|
32
32
|
"The install command used to install the release") { |arg| self.install_command = arg }
|
33
33
|
options.on("-b", "--before-download=command", String,
|
34
34
|
"The command executed before download starts") { |arg| self.before_download_command = arg }
|
35
|
+
options.on("-a", "--after-download=command", String,
|
36
|
+
"The command executed after download ends (or fails)") { |arg| self.after_download_command = arg }
|
37
|
+
options.on("-d", "--download-dir=directory", String,
|
38
|
+
"The direcotry where the release file will be temporary stored") { |arg| self.download_directory = arg }
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
@@ -70,11 +74,22 @@ module Box
|
|
70
74
|
Box::Release.execute! before_download_command if before_download_command
|
71
75
|
end
|
72
76
|
|
77
|
+
def after_download
|
78
|
+
Box::Release.execute! after_download_command if after_download_command
|
79
|
+
end
|
80
|
+
|
73
81
|
def upgrade
|
74
82
|
if latest and latest.newer?(current)
|
75
83
|
Box::Release.logger.info "New release : #{latest}"
|
84
|
+
Box::Release.download_directory = download_directory
|
76
85
|
before_download
|
77
|
-
|
86
|
+
|
87
|
+
begin
|
88
|
+
latest.download
|
89
|
+
ensure
|
90
|
+
after_download
|
91
|
+
end
|
92
|
+
|
78
93
|
Box::Release.logger.info "Replace #{current} with #{latest}"
|
79
94
|
latest.install :install_command => install_command
|
80
95
|
Box::Release.logger.info "Successfully installed #{latest}"
|
data/lib/box/release/memory.rb
CHANGED
data/lib/box/release/version.rb
CHANGED
@@ -8,9 +8,20 @@ describe Box::Release::Base do
|
|
8
8
|
|
9
9
|
subject { Box::Release::Memory.new }
|
10
10
|
|
11
|
-
|
11
|
+
describe "#file" do
|
12
|
+
|
13
|
+
context "by default" do
|
14
|
+
its(:file) { should == "/tmp/release.tar" }
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should use Box::Release.download_directory when defined" do
|
18
|
+
subject.stub :download_directory => "/dummy"
|
19
|
+
subject.file.should == "/dummy/release.tar"
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
12
23
|
|
13
|
-
describe "download" do
|
24
|
+
describe "#download" do
|
14
25
|
|
15
26
|
before(:each) do
|
16
27
|
FileUtils.rm_f(subject.file)
|
@@ -30,6 +30,19 @@ describe Box::Release::CLI do
|
|
30
30
|
|
31
31
|
end
|
32
32
|
|
33
|
+
describe "#download_directory" do
|
34
|
+
|
35
|
+
it "should be nil by default" do
|
36
|
+
subject.download_directory.should be_nil
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should use the value specified with --download-dir" do
|
40
|
+
subject.parse_options %w{--download-dir /dummy}
|
41
|
+
subject.download_directory.should == "/dummy"
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
33
46
|
describe "#url" do
|
34
47
|
|
35
48
|
it "should be nil by default" do
|
@@ -195,12 +208,30 @@ describe Box::Release::CLI do
|
|
195
208
|
|
196
209
|
let(:latest) { mock :name => "latest", :newer? => true, :download => true, :install => true }
|
197
210
|
|
211
|
+
it "should use download_directory as Box::Release.download_directory" do
|
212
|
+
subject.download_directory = "/dummy"
|
213
|
+
subject.upgrade
|
214
|
+
Box::Release.download_directory.should == "/dummy"
|
215
|
+
end
|
216
|
+
|
198
217
|
it "should invoke before_download ... before downloading latest release" do
|
199
218
|
subject.should_receive(:before_download).ordered
|
200
219
|
subject.latest.should_receive(:download).ordered
|
201
220
|
subject.upgrade
|
202
221
|
end
|
203
222
|
|
223
|
+
it "should invoke after_download ... after downloading latest release" do
|
224
|
+
subject.latest.should_receive(:download).ordered
|
225
|
+
subject.should_receive(:after_download).ordered
|
226
|
+
subject.upgrade
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should invoke after_download even if download fails" do
|
230
|
+
subject.latest.should_receive(:download).and_raise("fail")
|
231
|
+
subject.should_receive(:after_download)
|
232
|
+
lambda { subject.upgrade }.should raise_error
|
233
|
+
end
|
234
|
+
|
204
235
|
it "should download the latest release" do
|
205
236
|
subject.latest.should_receive(:download)
|
206
237
|
subject.upgrade
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: box-release
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alban Peignier
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-05-
|
19
|
+
date: 2011-05-19 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: activesupport
|
@@ -32,6 +32,34 @@ dependencies:
|
|
32
32
|
version: "0"
|
33
33
|
type: :runtime
|
34
34
|
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rcov
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
35
63
|
description: ""
|
36
64
|
email:
|
37
65
|
- alban@tryphon.eu
|