File tree Expand file tree Collapse file tree 3 files changed +16
-2
lines changed Expand file tree Collapse file tree 3 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,9 @@ appear at the top.
3232 and have a cleaner internal API. You can still completely disable the pool
3333 by setting ` SSHKit::Backend::Netssh.pool.idle_timeout = 0 ` .
3434 @mattbrictson @byroot [ PR #328 ] ( https://github.com/capistrano/sshkit/pull/328 )
35+ * Allow command map entries (` SSHKit::CommandMap#[] ` ) to be Procs
36+ [ PR #310 ] ((https://github.com/capistrano/sshkit/pull/310 )
37+ @mikz
3538
3639### Bug fixes
3740
Original file line number Diff line number Diff line change @@ -31,18 +31,20 @@ def [](command)
3131 end
3232 end
3333
34+ TO_VALUE = -> ( obj ) { obj . respond_to? ( :call ) ? obj . call : obj }
35+
3436 def initialize ( value = nil )
3537 @map = CommandHash . new ( value || defaults )
3638 end
3739
3840 def []( command )
3941 if prefix [ command ] . any?
40- prefixes = prefix [ command ] . map { | prefix | prefix . respond_to? ( :call ) ? prefix . call : prefix }
42+ prefixes = prefix [ command ] . map ( & TO_VALUE )
4143 prefixes = prefixes . join ( " " )
4244
4345 "#{ prefixes } #{ command } "
4446 else
45- @map [ command ]
47+ TO_VALUE . ( @map [ command ] )
4648 end
4749 end
4850
Original file line number Diff line number Diff line change @@ -16,6 +16,15 @@ def test_setter
1616 assert_equal map [ :rake ] , "/usr/local/rbenv/shims/rake"
1717 end
1818
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+
1928 def test_prefix
2029 map = CommandMap . new
2130 map . prefix [ :rake ] . push ( "/home/vagrant/.rbenv/bin/rbenv exec" )
You can’t perform that action at this time.
0 commit comments