reservoir 0.0.4 → 0.1.0
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/.gitignore +1 -0
- data/examples/rails_server.yml +7 -6
- data/lib/reservoir/application.rb +37 -14
- data/lib/reservoir/project.rb +16 -8
- data/lib/reservoir/version.rb +1 -1
- data/spec/application_spec.rb +52 -34
- data/spec/project_spec.rb +19 -2
- data/spec/sample_project.yml +2 -2
- data/spec/sample_project2.yml +3 -2
- data/spec/sample_project3.yml +9 -0
- metadata +11 -9
data/.gitignore
CHANGED
data/examples/rails_server.yml
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
version: 0.0
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
version: 0.1.0
|
2
|
+
display:
|
3
|
+
filename: @@SERVER_NAME@@.reservoir
|
4
|
+
mode: data_only
|
5
|
+
remotes:
|
6
|
+
- user: deployer
|
7
|
+
server: a4word.com
|
7
8
|
scripts:
|
8
9
|
- name: ruby
|
9
10
|
- name: rvm
|
@@ -2,17 +2,21 @@ module Reservoir
|
|
2
2
|
|
3
3
|
class Application
|
4
4
|
|
5
|
-
attr_accessor :
|
5
|
+
attr_accessor :display
|
6
6
|
|
7
7
|
def initialize(data = {})
|
8
|
-
@
|
8
|
+
@display = data[:display] || :stdio
|
9
|
+
@file_resets = []
|
10
|
+
@version_displayed_already = false
|
9
11
|
end
|
10
12
|
|
11
|
-
def
|
12
|
-
@
|
13
|
+
def display=(val)
|
14
|
+
@display = val || :stdio
|
13
15
|
end
|
14
16
|
|
15
|
-
def
|
17
|
+
def version_message
|
18
|
+
return nil if @version_displayed_already
|
19
|
+
@version_displayed_already = true
|
16
20
|
print "reservoir, version #{Reservoir::VERSION}\n"
|
17
21
|
end
|
18
22
|
|
@@ -25,7 +29,7 @@ module Reservoir
|
|
25
29
|
end
|
26
30
|
|
27
31
|
def project_message(project)
|
28
|
-
print "
|
32
|
+
print "server: #{project.name}\nfile: #{project.file}\n"
|
29
33
|
end
|
30
34
|
|
31
35
|
def which_version_message(script,version,path)
|
@@ -39,14 +43,14 @@ module Reservoir
|
|
39
43
|
usage_message
|
40
44
|
return
|
41
45
|
end
|
42
|
-
|
43
|
-
welcome_message
|
44
46
|
|
45
47
|
if ["--version","-version","-v","--v","version"].include?(args[0])
|
48
|
+
version_message
|
46
49
|
return
|
47
50
|
end
|
48
51
|
|
49
52
|
if ["--help","-help","-h","--h","help"].include?(args[0])
|
53
|
+
version_message
|
50
54
|
usage_message
|
51
55
|
return
|
52
56
|
end
|
@@ -55,8 +59,10 @@ module Reservoir
|
|
55
59
|
args.each do |filename|
|
56
60
|
all_projects = Project.load_from_file(filename)
|
57
61
|
all_projects.each do |p|
|
58
|
-
|
59
|
-
|
62
|
+
self.display = p.display
|
63
|
+
self.flush
|
64
|
+
version_message
|
65
|
+
project_message(p) unless is_data_only?
|
60
66
|
p.scripts.each do |script|
|
61
67
|
which_script = p.template(WhichScript)
|
62
68
|
version = p.template(Version)
|
@@ -69,18 +75,35 @@ module Reservoir
|
|
69
75
|
rescue
|
70
76
|
exception_message($!)
|
71
77
|
end
|
72
|
-
|
78
|
+
end
|
79
|
+
|
80
|
+
def flush
|
81
|
+
return if @file_resets.include?(display)
|
82
|
+
return unless is_file?
|
83
|
+
@version_displayed_already = false
|
84
|
+
@file_resets<< display
|
85
|
+
File.delete(@display[:filename]) if File.exist?(@display[:filename])
|
73
86
|
end
|
74
87
|
|
75
88
|
def print(output)
|
76
|
-
if @
|
89
|
+
if @display == :stdio
|
77
90
|
STDOUT.puts output
|
78
|
-
elsif
|
79
|
-
open(@
|
91
|
+
elsif is_file?
|
92
|
+
open(@display[:filename], 'a+') { |f| f.puts(output) }
|
80
93
|
else
|
81
94
|
output
|
82
95
|
end
|
83
96
|
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def is_file?
|
101
|
+
@display.kind_of?(Hash) && !@display[:filename].nil?
|
102
|
+
end
|
103
|
+
|
104
|
+
def is_data_only?
|
105
|
+
@display.kind_of?(Hash) && @display[:mode] == "data_only"
|
106
|
+
end
|
84
107
|
|
85
108
|
end
|
86
109
|
|
data/lib/reservoir/project.rb
CHANGED
@@ -2,27 +2,26 @@ module Reservoir
|
|
2
2
|
|
3
3
|
class Project
|
4
4
|
|
5
|
-
attr_accessor :scripts, :file, :remote_user, :remote_server, :
|
5
|
+
attr_accessor :scripts, :file, :remote_user, :remote_server, :display
|
6
6
|
|
7
7
|
def initialize(data = {})
|
8
8
|
@file = data[:file]
|
9
9
|
@remote_user = data[:remote_user]
|
10
10
|
@remote_server = data[:remote_server]
|
11
11
|
@scripts = data[:scripts] || []
|
12
|
-
@
|
12
|
+
@display = Project.sym_entries(data[:display]) || :stdio
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.load_from_file(file)
|
16
16
|
options = YAML::load( File.open( file ) )
|
17
|
-
default_args = { file: file, scripts: options["scripts"].each.collect { |script| script["name"] },
|
18
|
-
|
17
|
+
default_args = { file: file, scripts: options["scripts"].each.collect { |script| script["name"] }, display: sym_entries(options["display"]) }
|
19
18
|
all_projects = []
|
20
19
|
all_servers = options["remotes"]
|
21
20
|
if all_servers.nil?
|
22
21
|
all_projects << Project.new(default_args)
|
23
22
|
else
|
24
23
|
all_servers.each do |remote|
|
25
|
-
all_projects << Project.new(default_args.merge( remote_user: remote["user"], remote_server: remote["server"],
|
24
|
+
all_projects << Project.new(default_args.merge( remote_user: remote["user"], remote_server: remote["server"], display: resolve_placeholders(default_args[:display],remote)))
|
26
25
|
end
|
27
26
|
end
|
28
27
|
all_projects
|
@@ -39,11 +38,20 @@ module Reservoir
|
|
39
38
|
end
|
40
39
|
|
41
40
|
private
|
42
|
-
|
41
|
+
|
42
|
+
def self.sym_entries(var)
|
43
|
+
return var if var.nil? || var.kind_of?(Symbol)
|
44
|
+
return var.to_sym if var.kind_of?(String)
|
45
|
+
results = {}
|
46
|
+
var.each { |key,val| results[key.to_sym] = val }
|
47
|
+
results
|
48
|
+
end
|
49
|
+
|
43
50
|
def self.resolve_placeholders(var,remote)
|
44
51
|
return var if var.nil?
|
45
|
-
|
46
|
-
var
|
52
|
+
results = {}
|
53
|
+
var.each { |key,val| results[key.to_sym] = val.gsub("@@SERVER_NAME@@",remote["server"]) }
|
54
|
+
results
|
47
55
|
end
|
48
56
|
|
49
57
|
end
|
data/lib/reservoir/version.rb
CHANGED
data/spec/application_spec.rb
CHANGED
@@ -7,8 +7,10 @@ module Reservoir
|
|
7
7
|
before (:each) do
|
8
8
|
@project_file = File.dirname(__FILE__) + '/sample_project.yml'
|
9
9
|
@project_file2 = File.dirname(__FILE__) + '/sample_project2.yml'
|
10
|
+
@project_file3 = File.dirname(__FILE__) + '/sample_project3.yml'
|
11
|
+
|
10
12
|
@application = Application.new
|
11
|
-
@application.
|
13
|
+
@application.display = :string
|
12
14
|
|
13
15
|
Caller.stub!(:exec).with("which ruby").and_return("/path/to/ruby")
|
14
16
|
Caller.stub!(:exec).with("which rvm").and_return("/path/to/rvm")
|
@@ -32,12 +34,12 @@ module Reservoir
|
|
32
34
|
describe "#run" do
|
33
35
|
|
34
36
|
describe "no args" do
|
35
|
-
|
37
|
+
|
36
38
|
it "should handle nil args" do
|
37
39
|
@application.should_receive(:usage_message)
|
38
40
|
@application.run(nil)
|
39
41
|
end
|
40
|
-
|
42
|
+
|
41
43
|
it "should handle empty args" do
|
42
44
|
@application.should_receive(:usage_message)
|
43
45
|
@application.run([])
|
@@ -46,22 +48,22 @@ module Reservoir
|
|
46
48
|
end
|
47
49
|
|
48
50
|
describe "help" do
|
49
|
-
|
51
|
+
|
50
52
|
["--help","-help","-h","--h","help"].each do |help_name|
|
51
53
|
it "should support --help" do
|
52
|
-
@application.should_receive(:
|
54
|
+
@application.should_receive(:version_message)
|
53
55
|
@application.should_receive(:usage_message)
|
54
56
|
@application.run([help_name])
|
55
57
|
end
|
56
58
|
end
|
57
|
-
|
59
|
+
|
58
60
|
end
|
59
61
|
|
60
62
|
describe "version" do
|
61
|
-
|
63
|
+
|
62
64
|
["--version","-version","-v","--v","version"].each do |help_name|
|
63
65
|
it "should support --help" do
|
64
|
-
@application.should_receive(:
|
66
|
+
@application.should_receive(:version_message)
|
65
67
|
@application.should_not_receive(:exception_message)
|
66
68
|
@application.run([help_name])
|
67
69
|
end
|
@@ -72,7 +74,6 @@ module Reservoir
|
|
72
74
|
describe "invalid project file" do
|
73
75
|
|
74
76
|
it "should fail gracefully" do
|
75
|
-
@application.should_receive(:welcome_message)
|
76
77
|
@application.should_receive(:exception_message)
|
77
78
|
@application.run(["blah.yml"])
|
78
79
|
end
|
@@ -80,9 +81,9 @@ module Reservoir
|
|
80
81
|
end
|
81
82
|
|
82
83
|
describe "valid project files" do
|
83
|
-
|
84
|
+
|
84
85
|
it "should handle one file" do
|
85
|
-
@application.should_receive(:
|
86
|
+
@application.should_receive(:version_message)
|
86
87
|
@application.should_receive(:project_message)
|
87
88
|
@application.should_receive(:which_version_message).with("ruby","1.2.3","/path/to/ruby")
|
88
89
|
@application.should_receive(:which_version_message).with("rvm","1.2.4","/path/to/rvm")
|
@@ -90,55 +91,72 @@ module Reservoir
|
|
90
91
|
@application.should_not_receive(:exception_message)
|
91
92
|
@application.run([@project_file])
|
92
93
|
end
|
93
|
-
|
94
|
+
|
94
95
|
it "should handle multiple file" do
|
95
|
-
@application.should_receive(:
|
96
|
+
@application.should_receive(:version_message).exactly(2).times
|
96
97
|
@application.should_receive(:project_message).exactly(2).times
|
97
98
|
@application.should_receive(:which_version_message).exactly(4).times
|
98
99
|
@application.should_not_receive(:exception_message)
|
99
100
|
@application.run([@project_file,@project_file2])
|
100
|
-
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should save files to disk" do
|
104
|
+
@application.run([@project_file,@project_file2])
|
105
|
+
File.exists?("a4word.com.reservoir").should == true
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
it "should clean up existing files" do
|
110
|
+
open("a4word.com.reservoir", 'a+') { |f| f.puts("garble") }
|
111
|
+
@application.run([@project_file,@project_file2])
|
112
|
+
IO.read("a4word.com.reservoir").should == "reservoir, version 0.1.0\nserver: aforward@a4word.com\nfile: /Users/aforward/tp/projects/cenx/reservoir/spec/sample_project2.yml\nruby : 1.2.6 : /path/to/a4word/ruby\n"
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should support mode: data_only" do
|
116
|
+
open("a4word.com.reservoir", 'a+') { |f| f.puts("garble") }
|
117
|
+
@application.run([@project_file3])
|
118
|
+
IO.read("a4word.com.reservoir").should == "reservoir, version 0.1.0\nruby : 1.2.6 : /path/to/a4word/ruby\n"
|
101
119
|
end
|
102
120
|
|
103
121
|
end
|
104
122
|
|
105
123
|
end
|
106
|
-
|
107
|
-
describe "#
|
124
|
+
|
125
|
+
describe "#display" do
|
108
126
|
|
109
127
|
it "should be settable" do
|
110
|
-
@application.
|
111
|
-
@application.
|
128
|
+
@application.display = :a
|
129
|
+
@application.display.should == :a
|
112
130
|
end
|
113
131
|
|
114
132
|
it "should default to stdio" do
|
115
|
-
@application.
|
116
|
-
@application.
|
133
|
+
@application.display = nil
|
134
|
+
@application.display.should == :stdio
|
117
135
|
end
|
118
136
|
|
119
137
|
it "should default to :stdio" do
|
120
|
-
Application.new.
|
138
|
+
Application.new.display.should == :stdio
|
121
139
|
end
|
122
140
|
|
123
141
|
it "should be settable in constructor" do
|
124
|
-
Application.new(
|
142
|
+
Application.new(display: :blah).display.should == :blah
|
125
143
|
end
|
126
144
|
|
127
145
|
end
|
128
|
-
|
146
|
+
|
129
147
|
describe "#messages" do
|
130
148
|
|
131
|
-
it "should
|
132
|
-
@application.
|
149
|
+
it "should version_message" do
|
150
|
+
@application.version_message.should == "reservoir, version 0.1.0\n"
|
133
151
|
end
|
134
|
-
|
152
|
+
|
135
153
|
it "should usage_message" do
|
136
154
|
@application.usage_message.should == "USAGE: reservoir <project_file1> <project_file2> ...\n or reservoir help to see this message\n"
|
137
155
|
end
|
138
156
|
|
139
157
|
it "should project_message" do
|
140
158
|
p = Project.new(file: "blah.txt")
|
141
|
-
@application.project_message(p).should == "
|
159
|
+
@application.project_message(p).should == "server: local\nfile: blah.txt\n"
|
142
160
|
end
|
143
161
|
|
144
162
|
it "should exception_message" do
|
@@ -148,29 +166,29 @@ module Reservoir
|
|
148
166
|
@application.exception_message($!).split("\n")[0].should == "ERROR: No such file or directory - garble.txt"
|
149
167
|
end
|
150
168
|
end
|
151
|
-
|
169
|
+
|
152
170
|
it "should which_version_message" do
|
153
171
|
@application.which_version_message("a","1.2.3","/path/to/a").should == "a : 1.2.3 : /path/to/a\n"
|
154
172
|
end
|
155
|
-
|
173
|
+
|
156
174
|
|
157
175
|
end
|
158
176
|
|
159
177
|
describe "#print" do
|
160
178
|
|
161
|
-
it "should return a string if
|
162
|
-
@application.
|
179
|
+
it "should return a string if display :string" do
|
180
|
+
@application.display = :string
|
163
181
|
@application.print("x").should == "x"
|
164
182
|
end
|
165
183
|
|
166
|
-
it "should write to output if
|
184
|
+
it "should write to output if display :stdio" do
|
167
185
|
STDOUT.should_receive(:puts).with("x")
|
168
|
-
@application.
|
186
|
+
@application.display = :stdio
|
169
187
|
@application.print("x")
|
170
188
|
end
|
171
189
|
|
172
190
|
it "should write to file" do
|
173
|
-
@application.
|
191
|
+
@application.display = { filename: "output.txt" }
|
174
192
|
@application.print("x")
|
175
193
|
@application.print("y")
|
176
194
|
IO.read("output.txt").should == "x\ny\n"
|
data/spec/project_spec.rb
CHANGED
@@ -19,6 +19,23 @@ module Reservoir
|
|
19
19
|
Project.new(remote_server: "a4word.com", remote_user: "deployer").name.should == "deployer@a4word.com"
|
20
20
|
end
|
21
21
|
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "display" do
|
25
|
+
|
26
|
+
it "should default to stdio" do
|
27
|
+
Project.new.display.should == :stdio
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should assume strings are files" do
|
31
|
+
Project.new(display: { :filename => "blah" }).display.should == { filename: "blah" }
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should assume symbols are as-is" do
|
35
|
+
Project.new(display: :string).display.should == :string
|
36
|
+
end
|
37
|
+
|
38
|
+
|
22
39
|
end
|
23
40
|
|
24
41
|
describe "#load_from_file" do
|
@@ -30,7 +47,7 @@ module Reservoir
|
|
30
47
|
all.size.should == 1
|
31
48
|
project = all.first
|
32
49
|
project.scripts.should == [ "ruby", "rvm", "node"]
|
33
|
-
project.
|
50
|
+
project.display.should == :string
|
34
51
|
end
|
35
52
|
|
36
53
|
end
|
@@ -47,7 +64,7 @@ module Reservoir
|
|
47
64
|
t = project.template(clazz)
|
48
65
|
t.remote_user.should == 'aforward'
|
49
66
|
t.remote_server.should == 'a4word.com'
|
50
|
-
project.
|
67
|
+
project.display.should == { :filename => "a4word.com.reservoir" }
|
51
68
|
end
|
52
69
|
|
53
70
|
it "should ignore remote data if not set" do
|
data/spec/sample_project.yml
CHANGED
data/spec/sample_project2.yml
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reservoir
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-09-15 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70307851600340 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70307851600340
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: autotest
|
27
|
-
requirement: &
|
27
|
+
requirement: &70307851599920 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70307851599920
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: autotest-fsevent
|
38
|
-
requirement: &
|
38
|
+
requirement: &70307851599460 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70307851599460
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rb-fsevent
|
49
|
-
requirement: &
|
49
|
+
requirement: &70307851599040 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70307851599040
|
58
58
|
description: Helps manage cloud-based server instances by enumerating, comparing and
|
59
59
|
diff'ing application configurations
|
60
60
|
email:
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- spec/project_spec.rb
|
85
85
|
- spec/sample_project.yml
|
86
86
|
- spec/sample_project2.yml
|
87
|
+
- spec/sample_project3.yml
|
87
88
|
- spec/spec_helper.rb
|
88
89
|
- spec/version_spec.rb
|
89
90
|
- spec/which_script_spec.rb
|
@@ -117,6 +118,7 @@ test_files:
|
|
117
118
|
- spec/project_spec.rb
|
118
119
|
- spec/sample_project.yml
|
119
120
|
- spec/sample_project2.yml
|
121
|
+
- spec/sample_project3.yml
|
120
122
|
- spec/spec_helper.rb
|
121
123
|
- spec/version_spec.rb
|
122
124
|
- spec/which_script_spec.rb
|