A /etc/hosts parser. Also supports writing groups of data to the file.
# File lib/phusion_passenger/utils/hosts_file_parser.rb, line 29 def self.flush_dns_cache! if RUBY_PLATFORM =~ /darwin/ system("dscacheutil -flushcache") end end
# File lib/phusion_passenger/utils/hosts_file_parser.rb, line 35 def initialize(filename_or_io = "/etc/hosts") if filename_or_io.respond_to?(:readline) read_and_parse(filename_or_io) else File.open(filename_or_io, "rb") do |f| read_and_parse(f) end end end
# File lib/phusion_passenger/utils/hosts_file_parser.rb, line 66 def add_group_data(marker, data) begin_index = find_line(0, "###### BEGIN #{marker} ######") end_index = find_line(begin_index + 1, "###### END #{marker} ######") if begin_index if begin_index && end_index @lines[begin_index + 1 .. end_index - 1] = data.split("\n") else @lines << "###### BEGIN #{marker} ######" @lines.concat(data.split("\n")) @lines << "###### END #{marker} ######" end end
# File lib/phusion_passenger/utils/hosts_file_parser.rb, line 49 def host_count return @host_names.size end
# File lib/phusion_passenger/utils/hosts_file_parser.rb, line 45 def ip_count return @ips.size end
# File lib/phusion_passenger/utils/hosts_file_parser.rb, line 53 def resolve(host_name) if host_name.downcase == "localhost" return "127.0.0.1" else return @host_names[host_name.downcase] end end
Generated with the Darkfish Rdoc Generator 2.