class SshConfig::Loader
For loading an ssh_config(5) file.
Public Instance Methods
parse(str)
click to toggle source
# File lib/ssh_config/loader.rb, line 7 def parse(str) parse_lines(str.to_str.split(/[\n\r]+/)) end
parse_lines(strings)
click to toggle source
# File lib/ssh_config/loader.rb, line 11 def parse_lines(strings) Array(strings).map(&:to_str).each do |line| p_include(Regexp.last_match(1)) if line =~ /^\s*Include\s+(.*)/ p_host(Regexp.last_match(1)) if line =~ /^\s*Host\s+(.*)/ end results end
results()
click to toggle source
# File lib/ssh_config/loader.rb, line 20 def results @results ||= {} end
Private Instance Methods
add_entry(entry)
click to toggle source
# File lib/ssh_config/loader.rb, line 46 def add_entry(entry) entry.distinct_names.each { |host| results[host] = entry } end
p_host(arg)
click to toggle source
# File lib/ssh_config/loader.rb, line 26 def p_host(arg) hosts = arg .split(/\s+/) .reject { |host| host =~ /^\d|%|\*/ } add_entry(Entry.new(hosts)) unless hosts.empty? end
p_include(glob)
click to toggle source
# File lib/ssh_config/loader.rb, line 34 def p_include(glob) old_dir = Dir.pwd begin Dir.chdir File.expand_path('~/.ssh') Dir[glob.chomp].each do |fname| parse(File.read(fname)) end ensure Dir.chdir old_dir end end