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 @@ -15,6 +15,9 @@ appear at the top.
1515 @steved
1616 * ` SSHKit::Formatter::Abstract ` now accepts an optional Hash of options
1717 [ PR #308 ] ( https://github.com/capistrano/sshkit/pull/308 ) @mattbrictson
18+ * allow command map entries to be Procs
19+ [ PR #310 ] ((https://github.com/capistrano/sshkit/pull/310 )
20+ @mikz
1821
1922## 1.8.1
2023
Original file line number Diff line number Diff line change @@ -33,18 +33,20 @@ def [](command)
3333 end
3434 end
3535
36+ TO_VALUE = -> ( obj ) { obj . respond_to? ( :call ) ? obj . call : obj }
37+
3638 def initialize ( value = nil )
3739 @map = CommandHash . new ( value || defaults )
3840 end
3941
4042 def []( command )
4143 if prefix [ command ] . any?
42- prefixes = prefix [ command ] . map { | prefix | prefix . respond_to? ( :call ) ? prefix . call : prefix }
44+ prefixes = prefix [ command ] . map ( & TO_VALUE )
4345 prefixes = prefixes . join ( " " )
4446
4547 "#{ prefixes } #{ command } "
4648 else
47- @map [ command ]
49+ TO_VALUE . ( @map [ command ] )
4850 end
4951 end
5052
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