cape 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.markdown +4 -0
- data/lib/cape.rb +8 -4
- data/lib/cape/dsl.rb +6 -4
- data/lib/cape/rake.rb +46 -7
- data/lib/cape/version.rb +1 -1
- data/spec/cape/rake_spec.rb +75 -0
- data/spec/cape_spec.rb +6 -0
- metadata +4 -4
data/History.markdown
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Version history for the _Cape_ project
|
2
2
|
|
3
|
+
## <a name="v1.4.0"></a>v1.4.0, Mon 2/06/2012
|
4
|
+
|
5
|
+
* Cache the Rake task list to improve Capistrano responsiveness
|
6
|
+
|
3
7
|
## <a name="v1.3.0"></a>v1.3.0, Fri 2/03/2012
|
4
8
|
|
5
9
|
* Don’t allow `nil` environment variables to pass through to the remote command line
|
data/lib/cape.rb
CHANGED
@@ -40,10 +40,14 @@ end
|
|
40
40
|
def Cape(&block)
|
41
41
|
Cape.module_eval do
|
42
42
|
@outer_self = block.binding.eval('self', __FILE__, __LINE__)
|
43
|
-
|
44
|
-
block.
|
45
|
-
|
46
|
-
|
43
|
+
begin
|
44
|
+
if 0 < block.arity
|
45
|
+
block.call self
|
46
|
+
else
|
47
|
+
module_eval(&block)
|
48
|
+
end
|
49
|
+
ensure
|
50
|
+
rake.expire_cache!
|
47
51
|
end
|
48
52
|
end
|
49
53
|
Cape
|
data/lib/cape/dsl.rb
CHANGED
@@ -215,6 +215,12 @@ module Cape
|
|
215
215
|
rake.remote_executable = value
|
216
216
|
end
|
217
217
|
|
218
|
+
protected
|
219
|
+
|
220
|
+
def rake
|
221
|
+
@rake ||= Rake.new
|
222
|
+
end
|
223
|
+
|
218
224
|
private
|
219
225
|
|
220
226
|
def deployment_library
|
@@ -230,10 +236,6 @@ module Cape
|
|
230
236
|
end
|
231
237
|
end
|
232
238
|
|
233
|
-
def rake
|
234
|
-
@rake ||= Rake.new
|
235
|
-
end
|
236
|
-
|
237
239
|
end
|
238
240
|
|
239
241
|
end
|
data/lib/cape/rake.rb
CHANGED
@@ -6,12 +6,6 @@ module Cape
|
|
6
6
|
# The default command used to run Rake.
|
7
7
|
DEFAULT_EXECUTABLE = '/usr/bin/env rake'.freeze
|
8
8
|
|
9
|
-
# Sets the command used to run Rake on the local computer.
|
10
|
-
#
|
11
|
-
# @param [String] value the command used to run Rake on the local computer
|
12
|
-
# @return [String] _value_
|
13
|
-
attr_writer :local_executable
|
14
|
-
|
15
9
|
# Sets the command used to run Rake on remote computers.
|
16
10
|
#
|
17
11
|
# @param [String] value the command used to run Rake on remote computers
|
@@ -52,7 +46,7 @@ module Cape
|
|
52
46
|
::Regexp.escape(task_expression.to_s) :
|
53
47
|
'.+?'
|
54
48
|
regexp = /^rake (#{task_expression}(?::.+?)?)(?:\[(.+?)\])?\s+# (.+)/
|
55
|
-
|
49
|
+
each_output_line do |l|
|
56
50
|
unless (matches = l.chomp.match(regexp))
|
57
51
|
next
|
58
52
|
end
|
@@ -74,6 +68,12 @@ module Cape
|
|
74
68
|
self
|
75
69
|
end
|
76
70
|
|
71
|
+
# Forces cached Rake task metadata (if any) to be discarded.
|
72
|
+
def expire_cache!
|
73
|
+
@output_lines = nil
|
74
|
+
self
|
75
|
+
end
|
76
|
+
|
77
77
|
# The command used to run Rake on the local computer.
|
78
78
|
#
|
79
79
|
# @return [String] the command used to run Rake on the local computer
|
@@ -83,6 +83,21 @@ module Cape
|
|
83
83
|
@local_executable ||= DEFAULT_EXECUTABLE
|
84
84
|
end
|
85
85
|
|
86
|
+
# Sets the command used to run Rake on the local computer and discards any
|
87
|
+
# cached Rake task metadata.
|
88
|
+
#
|
89
|
+
# @param [String] value the command used to run Rake on the local computer
|
90
|
+
# @return [String] _value_
|
91
|
+
#
|
92
|
+
# @see #expire_cache!
|
93
|
+
def local_executable=(value)
|
94
|
+
unless @local_executable == value
|
95
|
+
@local_executable = value
|
96
|
+
expire_cache!
|
97
|
+
end
|
98
|
+
value
|
99
|
+
end
|
100
|
+
|
86
101
|
# The command used to run Rake on remote computers.
|
87
102
|
#
|
88
103
|
# @return [String] the command used to run Rake on remote computers
|
@@ -92,6 +107,30 @@ module Cape
|
|
92
107
|
@remote_executable ||= DEFAULT_EXECUTABLE
|
93
108
|
end
|
94
109
|
|
110
|
+
private
|
111
|
+
|
112
|
+
def each_output_line(&block)
|
113
|
+
if @output_lines
|
114
|
+
@output_lines.each(&block)
|
115
|
+
return self
|
116
|
+
end
|
117
|
+
|
118
|
+
@output_lines = []
|
119
|
+
begin
|
120
|
+
fetch_output.each_line do |l|
|
121
|
+
@output_lines << l
|
122
|
+
block.call(l)
|
123
|
+
end
|
124
|
+
rescue
|
125
|
+
expire_cache!
|
126
|
+
raise
|
127
|
+
end
|
128
|
+
self
|
129
|
+
end
|
130
|
+
|
131
|
+
def fetch_output
|
132
|
+
`#{local_executable} --tasks 2> /dev/null`
|
133
|
+
end
|
95
134
|
end
|
96
135
|
|
97
136
|
end
|
data/lib/cape/version.rb
CHANGED
data/spec/cape/rake_spec.rb
CHANGED
@@ -37,4 +37,79 @@ describe Cape::Rake do
|
|
37
37
|
|
38
38
|
its(:remote_executable) { should == 'completely different' }
|
39
39
|
end
|
40
|
+
|
41
|
+
describe 'caching: ' do
|
42
|
+
before :each do
|
43
|
+
subject.stub!(:fetch_output).and_return output
|
44
|
+
end
|
45
|
+
|
46
|
+
let(:output) {
|
47
|
+
<<-end_output
|
48
|
+
rake foo # foo
|
49
|
+
rake bar # bar
|
50
|
+
rake baz # baz
|
51
|
+
end_output
|
52
|
+
}
|
53
|
+
|
54
|
+
describe '#each_task' do
|
55
|
+
it 'should build and use a cache' do
|
56
|
+
subject.should_receive(:fetch_output).once.and_return output
|
57
|
+
subject.each_task do |t|
|
58
|
+
end
|
59
|
+
subject.each_task do |t|
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should not expire the cache' do
|
64
|
+
subject.should_not_receive :expire_cache!
|
65
|
+
subject.each_task do |t|
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should expire the cache in the event of an error' do
|
70
|
+
subject.should_receive(:expire_cache!).once
|
71
|
+
begin
|
72
|
+
subject.each_task do |t|
|
73
|
+
raise 'pow!'
|
74
|
+
end
|
75
|
+
rescue
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should not swallow errors' do
|
80
|
+
lambda {
|
81
|
+
subject.each_task do |t|
|
82
|
+
raise ZeroDivisionError, 'pow!'
|
83
|
+
end
|
84
|
+
}.should raise_error(ZeroDivisionError, 'pow!')
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#expire_cache!' do
|
89
|
+
it 'should expire the cache' do
|
90
|
+
subject.should_receive(:fetch_output).twice.and_return output
|
91
|
+
subject.each_task do |t|
|
92
|
+
end
|
93
|
+
subject.expire_cache!
|
94
|
+
subject.each_task do |t|
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#local_executable=' do
|
100
|
+
describe 'with the same value' do
|
101
|
+
it 'should not expire the cache' do
|
102
|
+
subject.should_not_receive :expire_cache!
|
103
|
+
subject.local_executable = subject.local_executable
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe 'with a different value' do
|
108
|
+
it 'should expire the cache' do
|
109
|
+
subject.should_receive(:expire_cache!).once
|
110
|
+
subject.local_executable = subject.local_executable + ' foo'
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
40
115
|
end
|
data/spec/cape_spec.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cape
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
8
|
+
- 4
|
9
9
|
- 0
|
10
|
-
version: 1.
|
10
|
+
version: 1.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nils Jonsson
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-02-
|
18
|
+
date: 2012-02-06 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: aruba
|