public
Fork of relevance/smoke_signals
Description: CruiseControl.rb Campfire notifications
Homepage: http://opensource.thinkrelevance.com/wiki/smoke_signals
Clone URL: git://github.com/reagent/smoke_signals.git
Improve installer; add USAGE when installer fails
reagent (author)
Wed Apr 23 06:29:43 -0700 2008
commit  efcdae51116aa39c708841c4c83c3e4b9ef5127e
tree    9701707e9a8ebc585fc2140372890718a8fed4d0
parent  8288bd177a0fba934232f24761e086454f7397e6
...
29
30
31
32
 
33
34
35
...
29
30
31
 
32
33
34
35
0
@@ -29,7 +29,7 @@ spec = Gem::Specification.new do |s|
0
   s.executables = ['smoke_signals']
0
   
0
   s.require_path = 'lib'
0
- s.files = %w(README Rakefile init.rb) + Dir.glob("{lib,specs,config}/**/*")
0
+ s.files = %w(README USAGE Rakefile init.rb) + Dir.glob("{lib,specs,config}/**/*")
0
 end
0
 
0
 Rake::GemPackageTask.new(spec) do |pkg|
0
bin/smoke_signals 100644 →
...
2
3
4
5
6
7
 
 
 
 
 
 
 
8
...
2
3
4
 
 
 
5
6
7
8
9
10
11
12
0
@@ -2,7 +2,11 @@
0
 
0
 require 'installer'
0
 
0
-Installer.run(`pwd`) do |installer|
0
- installer.copy_configuration
0
- installer.copy_plugin
0
+begin
0
+ command = ARGV[0].strip
0
+ success = Installer.run(command, `pwd`)
0
+ puts "Command '#{command}' #{success ? 'was successful' : 'failed'}"
0
+rescue Installer::InvalidCommandError
0
+ puts "Invalid command"
0
+ puts File.read(File.join(File.dirname(__FILE__), %w(.. USAGE)))
0
 end
...
1
2
3
 
 
 
 
4
5
 
 
 
 
6
7
8
9
10
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
13
14
...
30
31
32
 
 
 
 
33
34
35
...
37
38
39
 
 
 
 
40
41
...
1
2
 
3
4
5
6
7
 
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
...
54
55
56
57
58
59
60
61
62
63
...
65
66
67
68
69
70
71
72
73
0
@@ -1,14 +1,38 @@
0
 class Installer
0
 
0
- def self.run(path, &block)
0
+ class InvalidCommandError < StandardError; end
0
+
0
+ def self.run(command, path)
0
+ raise InvalidCommandError unless %w(install uninstall).include?(command)
0
     installer = Installer.new(path)
0
- yield installer if installer.at_root?
0
+
0
+ success = installer.at_root?
0
+ success = success && installer.send(command)
0
+ success
0
   end
0
   
0
   def initialize(path)
0
     @path = path.strip
0
   end
0
   
0
+ def uninstall
0
+ uninstall = self.installed?
0
+ if uninstall
0
+ self.remove_configuration
0
+ self.remove_plugin
0
+ end
0
+ uninstall
0
+ end
0
+
0
+ def install
0
+ install = !self.installed?
0
+ if install
0
+ self.copy_configuration
0
+ self.copy_plugin
0
+ end
0
+ install
0
+ end
0
+
0
   def installed?
0
     installed = true
0
     files = ['config/smoke_signals.yml', 'builder_plugins/installed/smoke_signals']
0
@@ -30,6 +54,10 @@ class Installer
0
     copy
0
   end
0
   
0
+ def remove_configuration
0
+ FileUtils.rm("#{@path}/config/smoke_signals.yml")
0
+ end
0
+
0
   def copy_plugin
0
     lib_dir = File.dirname(__FILE__)
0
     FileUtils.mkdir("#{@path}/builder_plugins/installed/smoke_signals")
0
@@ -37,4 +65,8 @@ class Installer
0
     FileUtils.cp_r("#{lib_dir}", "#{@path}/builder_plugins/installed/smoke_signals/")
0
   end
0
   
0
+ def remove_plugin
0
+ FileUtils.rm_rf("#{@path}/builder_plugins/installed/smoke_signals")
0
+ end
0
+
0
 end
0
\ No newline at end of file
...
44
45
46
47
 
48
49
50
...
55
56
57
 
 
 
 
 
 
 
 
 
 
58
59
60
61
62
63
 
 
 
 
64
65
 
 
 
 
 
 
 
66
67
68
69
70
 
 
 
 
 
 
 
 
 
71
72
73
74
75
76
77
 
 
 
 
78
 
 
 
 
 
 
79
80
81
82
83
84
 
 
 
 
 
 
 
 
 
 
85
86
 
 
 
 
 
 
87
...
44
45
46
 
47
48
49
50
...
55
56
57
58
59
60
61
62
63
64
65
66
67
68
 
 
 
 
 
69
70
71
72
73
 
74
75
76
77
78
79
80
81
 
 
 
 
82
83
84
85
86
87
88
89
90
91
92
 
 
 
 
 
93
94
95
96
97
98
99
100
101
102
103
104
105
 
 
 
 
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
0
@@ -44,7 +44,7 @@ describe "Installer" do
0
     
0
     @installer.copy_configuration
0
   end
0
-
0
+
0
   it "should copy the plugin to the destination directory" do
0
     File.expects(:dirname).with(@installer_source_file).returns(@lib_path)
0
     plugin_dir = "#{@path}/builder_plugins/installed/smoke_signals"
0
@@ -55,33 +55,70 @@ describe "Installer" do
0
     
0
     @installer.copy_plugin
0
   end
0
+
0
+ it "should remove the configuration from the appropriate directory" do
0
+ FileUtils.expects(:rm).with("#{@path}/config/smoke_signals.yml")
0
+ @installer.remove_configuration
0
+ end
0
+
0
+ it "should remove the plugin from the appropriate directory" do
0
+ FileUtils.expects(:rm_rf).with("#{@path}/builder_plugins/installed/smoke_signals")
0
+ @installer.remove_plugin
0
+ end
0
 
0
- it "should not run any installation if it's not at the root directory" do
0
- installer_mock = mock()
0
- installer_mock.expects(:at_root?).returns(false)
0
- installer_mock.expects(:copy_configuration).never
0
- installer_mock.expects(:copy_plugin).never
0
+ it "should uninstall itself when it's installed" do
0
+ @installer.expects(:installed?).returns(true)
0
+ @installer.expects(:remove_configuration)
0
+ @installer.expects(:remove_plugin)
0
     
0
- Installer.expects(:new).with(@path).returns(installer_mock)
0
+ @installer.uninstall.should.be true
0
+ end
0
+
0
+ it "should not uninstall when it's not installed" do
0
+ @installer.expects(:installed?).returns(false)
0
+ @installer.expects(:remove_configuration).never
0
+ @installer.expects(:remove_plugin).never
0
     
0
- Installer.run(@path) do |installer|
0
- installer.copy_configuration
0
- installer.copy_plugin
0
- end
0
+ @installer.uninstall.should.be false
0
+ end
0
+
0
+ it "should install when it's not installed" do
0
+ @installer.expects(:installed?).returns(false)
0
+ @installer.expects(:copy_configuration)
0
+ @installer.expects(:copy_plugin)
0
+
0
+ @installer.install.should.be true
0
   end
0
   
0
- it "should run the installation if it's at the root directory" do
0
- installer_mock = mock()
0
- installer_mock.expects(:at_root?).returns(true)
0
- installer_mock.expects(:copy_configuration).once.with(nil)
0
- installer_mock.expects(:copy_plugin).once.with(nil)
0
+ it "should not install when it's installed" do
0
+ @installer.expects(:installed?).returns(true)
0
+ @installer.expects(:copy_configuration).never
0
+ @installer.expects(:copy_plugin).never
0
     
0
+ @installer.install.should.be false
0
+ end
0
+
0
+ it "should know which command to run" do
0
+ command = 'install'
0
+ installer_mock = mock(:at_root? => true, command.to_sym => true)
0
     Installer.expects(:new).with(@path).returns(installer_mock)
0
     
0
- Installer.run(@path) do |installer|
0
- installer.copy_configuration
0
- installer.copy_plugin
0
- end
0
+ Installer.run(command, @path).should.be true
0
+ end
0
+
0
+ it "should not run any commands if the installer isn't at the root directory" do
0
+ command = 'install'
0
+ installer_mock = mock(:at_root? => false)
0
+ installer_mock.expects(command).never
0
+
0
+ Installer.expects(:new).with(@path).returns(installer_mock)
0
+ Installer.run(command, @path).should.be false
0
   end
0
   
0
+ it "should raise an exception if the command isn't available" do
0
+ proc = lambda { Installer.run('bad_command', @path) }
0
+ proc.should.raise Installer::InvalidCommandError
0
+ end
0
+
0
+
0
 end

Comments

    No one has commented yet.