Class: SSH::Ident::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ssh/ident/config.rb

Overview

ssh ident config

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



18
19
20
# File 'lib/ssh/ident/config.rb', line 18

def initialize
  @values = load
end

Class Method Details

.defaultsObject



8
9
10
11
12
13
14
15
16
# File 'lib/ssh/ident/config.rb', line 8

def self.defaults
  {
      'FILE_USER_CONFIG' => "#{ENV['HOME']}/.ssh-ident",
      'DIR_IDENTITIES' => "#{ENV['HOME']}/.ssh/identities",
      'DIR_AGENTS' => "#{ENV['HOME']}/.ssh/agents",
      'DEFAULT_IDENTITY' => "#{ENV['USER']}",
      'SSH_ADD_OPTIONS' => '-t 7200'
  }
end

Instance Method Details

#get(param) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/ssh/ident/config.rb', line 31

def get(param)
  result = ENV[param]
  result ||= @values[param] if @values
  result ||= Config.defaults[param]
  fail "failed to find parameter #{param}" if result.nil?
  return File.expand_path(result) if result.is_a?(String) && result.include?('~')
  result
end

#loadObject



22
23
24
25
26
27
28
29
# File 'lib/ssh/ident/config.rb', line 22

def load
  if respond_to?(:load_custom)
    return load_custom
  end
  path = get('FILE_USER_CONFIG')
  return {} unless File.exist?(path)
  YAML.load(File.read(path))
end

#set(param, value) ⇒ Object



40
41
42
# File 'lib/ssh/ident/config.rb', line 40

def set(param, value)
  @values[param] = value
end