57: def load(file, host, settings={})
58: file = File.expand_path(file)
59: return settings unless File.readable?(file)
60:
61: matched_host = nil
62: multi_host = []
63: IO.foreach(file) do |line|
64: next if line =~ /^\s*(?:#.*)?$/
65:
66: if line =~ /^\s*(\S+)\s*=(.*)$/
67: key, value = $1, $2
68: else
69: key, value = line.strip.split(/\s+/, 2)
70: end
71:
72:
73: next if value.nil?
74:
75: key.downcase!
76: value = $1 if value =~ /^"(.*)"$/
77:
78: value = case value.strip
79: when /^\d+$/ then value.to_i
80: when /^no$/i then false
81: when /^yes$/i then true
82: else value
83: end
84:
85: if key == 'host'
86:
87:
88: multi_host = value.split(/,\s+/)
89: matched_host = multi_host.select { |h| host =~ pattern2regex(h) }.first
90: elsif !matched_host.nil?
91: if key == 'identityfile'
92: settings[key] ||= []
93: settings[key] << value
94: else
95: settings[key] = value unless settings.key?(key)
96: end
97: end
98: end
99:
100: return settings
101: end