Class: SSHKit::CommandMap

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

Defined Under Namespace

Classes: CommandHash, PrefixProvider

Instance Method Summary collapse

Constructor Details

#initialize(value = nil) ⇒ CommandMap

Returns a new instance of CommandMap.



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

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

Instance Method Details

#[](command) ⇒ Object



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

def [](command)
  if prefix[command].any?
    prefixes = prefix[command].map{ |prefix| prefix.respond_to?(:call) ? prefix.call : prefix }
    prefixes = prefixes.join(" ")

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

#[]=(command, new_command) ⇒ Object



55
56
57
# File 'lib/sshkit/command_map.rb', line 55

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

#clearObject



59
60
61
# File 'lib/sshkit/command_map.rb', line 59

def clear
  @map = CommandHash.new(defaults)
end

#defaultsObject



63
64
65
66
67
68
69
70
71
# File 'lib/sshkit/command_map.rb', line 63

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



51
52
53
# File 'lib/sshkit/command_map.rb', line 51

def prefix
  @prefix ||= PrefixProvider.new
end