Method: Hub::SshConfig#parse_file

Defined in:
lib/hub/ssh_config.rb

#parse_file(file) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/hub/ssh_config.rb', line 60

def parse_file file
  host_patterns = [HostPattern.new('*')]

  IO.foreach(file) do |line|
    case line
    when /^\s*(#|$)/ then next
    when /^\s*(\S+)\s*=/
      key, value = $1, $'
    else
      key, value = line.strip.split(/\s+/, 2)
    end

    next if value.nil?
    key.downcase!
    value = $1 if value =~ /^"(.*)"$/
    value.chomp!

    if 'host' == key
      host_patterns = value.split(/\s+/).map {|p| HostPattern.new p }
    else
      record_setting key, value, host_patterns
    end
  end
end