Module: Sconb::SSHConfig

Defined in:
lib/sconb/ssh_config.rb

Class Method Summary collapse

Class Method Details

.load(path, regexp_str = '.*', options = []) ⇒ Object



4
5
6
7
8
# File 'lib/sconb/ssh_config.rb', line 4

def load(path, regexp_str = '.*', options = [])
  file = File.expand_path(path)
  content = File.readable?(file) ? File.open(file).read : nil
  parse(content, regexp_str, options)
end

.parse(content, regexp_str = '.*', options = []) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/sconb/ssh_config.rb', line 10

def parse(content, regexp_str = '.*', options = [])
  @regexp = Regexp.new(regexp_str)
  @options = options
  @content = content
  @configs = {}
  return @configs if content.nil?
  @allconfig = Net::SSH::Config.parse_with_key(@content, '*', @options)
  @configs['*'] = @allconfig unless @allconfig.size <= 1
  @content.each_line do |line|
    parse_line(line)
  end
  @configs
end