File tree 3 files changed +16
-2
lines changed
3 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,9 @@ appear at the top.
15
15
@steved
16
16
* ` SSHKit::Formatter::Abstract ` now accepts an optional Hash of options
17
17
[ PR #308 ] ( https://github.com/capistrano/sshkit/pull/308 ) @mattbrictson
18
+ * allow command map entries (` SSHKit::CommandMap#[] ` ) to be Procs
19
+ [ PR #310 ] ((https://github.com/capistrano/sshkit/pull/310 )
20
+ @mikz
18
21
19
22
## 1.8.1
20
23
Original file line number Diff line number Diff line change @@ -33,18 +33,20 @@ def [](command)
33
33
end
34
34
end
35
35
36
+ TO_VALUE = -> ( obj ) { obj . respond_to? ( :call ) ? obj . call : obj }
37
+
36
38
def initialize ( value = nil )
37
39
@map = CommandHash . new ( value || defaults )
38
40
end
39
41
40
42
def []( command )
41
43
if prefix [ command ] . any?
42
- prefixes = prefix [ command ] . map { | prefix | prefix . respond_to? ( :call ) ? prefix . call : prefix }
44
+ prefixes = prefix [ command ] . map ( & TO_VALUE )
43
45
prefixes = prefixes . join ( " " )
44
46
45
47
"#{ prefixes } #{ command } "
46
48
else
47
- @map [ command ]
49
+ TO_VALUE . ( @map [ command ] )
48
50
end
49
51
end
50
52
Original file line number Diff line number Diff line change @@ -16,6 +16,15 @@ def test_setter
16
16
assert_equal map [ :rake ] , "/usr/local/rbenv/shims/rake"
17
17
end
18
18
19
+ def test_setter_procs
20
+ map = CommandMap . new
21
+ i = 0
22
+ map [ :rake ] = -> { i += 1 ; "/usr/local/rbenv/shims/rake#{ i } " }
23
+
24
+ assert_equal map [ :rake ] , "/usr/local/rbenv/shims/rake1"
25
+ assert_equal map [ :rake ] , "/usr/local/rbenv/shims/rake2"
26
+ end
27
+
19
28
def test_prefix
20
29
map = CommandMap . new
21
30
map . prefix [ :rake ] . push ( "/home/vagrant/.rbenv/bin/rbenv exec" )
You can’t perform that action at this time.
0 commit comments