Class: SSHKit::CommandMap

Inherits:
Object
  • Object
show all
Defined in:
lib/sshkit/command_map.rb

Defined Under Namespace

Classes: PrefixProvider

Instance Method Summary collapse

Constructor Details

#initialize(value = nil) ⇒ CommandMap

Returns a new instance of CommandMap.



15
16
17
# File 'lib/sshkit/command_map.rb', line 15

def initialize(value = nil)
  @map = value || defaults
end

Instance Method Details

#[](command) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/sshkit/command_map.rb', line 19

def [](command)
  if prefix[command].any?
    prefixes = prefix[command].join(" ")

    "#{prefixes} #{command}"
  else
    @map[command]
  end
end

#[]=(command, new_command) ⇒ Object



33
34
35
# File 'lib/sshkit/command_map.rb', line 33

def []=(command, new_command)
  @map[command] = new_command
end

#clearObject



37
38
39
# File 'lib/sshkit/command_map.rb', line 37

def clear
  @map = defaults
end

#defaultsObject



41
42
43
44
45
46
47
48
49
# File 'lib/sshkit/command_map.rb', line 41

def defaults
  Hash.new do |hash, command|
    if %w{if test time}.include? command.to_s
      hash[command] = command.to_s
    else
      hash[command] = "/usr/bin/env #{command}"
    end
  end
end

#prefixObject



29
30
31
# File 'lib/sshkit/command_map.rb', line 29

def prefix
  @prefix ||= PrefixProvider.new
end