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.



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

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

Instance Method Details

#[](command) ⇒ Object



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

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



53
54
55
# File 'lib/sshkit/command_map.rb', line 53

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

#clearObject



57
58
59
# File 'lib/sshkit/command_map.rb', line 57

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

#defaultsObject



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

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



49
50
51
# File 'lib/sshkit/command_map.rb', line 49

def prefix
  @prefix ||= PrefixProvider.new
end