Class: Ddig::Nameserver
- Inherits:
-
Object
- Object
- Ddig::Nameserver
- Defined in:
- lib/ddig/nameserver.rb
Instance Attribute Summary collapse
-
#servers ⇒ Object
readonly
Returns the value of attribute servers.
Instance Method Summary collapse
- #default_servers ⇒ Object
-
#initialize(nameservers: nil) ⇒ Nameserver
constructor
A new instance of Nameserver.
- #servers_ipv4 ⇒ Object
- #servers_ipv6 ⇒ Object
- #validation_servers ⇒ Object
Constructor Details
#initialize(nameservers: nil) ⇒ Nameserver
Returns a new instance of Nameserver.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ddig/nameserver.rb', line 7 def initialize(nameservers: nil) @nameservers = nameservers if @nameservers.nil? @servers = default_servers elsif @nameservers.is_a?(Array) @servers = @nameservers else @servers = [@nameservers] end validation_servers end |
Instance Attribute Details
#servers ⇒ Object (readonly)
Returns the value of attribute servers.
5 6 7 |
# File 'lib/ddig/nameserver.rb', line 5 def servers @servers end |
Instance Method Details
#default_servers ⇒ Object
29 30 31 |
# File 'lib/ddig/nameserver.rb', line 29 def default_servers Resolv::DNS::Config.default_config_hash[:nameserver] end |
#servers_ipv4 ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/ddig/nameserver.rb', line 33 def servers_ipv4 @servers.map do |nameserver| if IPAddr.new(nameserver).ipv4? nameserver end end.compact end |
#servers_ipv6 ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/ddig/nameserver.rb', line 41 def servers_ipv6 @servers.map do |nameserver| if IPAddr.new(nameserver).ipv6? nameserver end end.compact end |
#validation_servers ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ddig/nameserver.rb', line 49 def validation_servers @servers.uniq.each do |server| addr = IPAddr.new(server) rescue nil if addr.nil? puts "Warning: nameservers has invalid ip address (nameserver: #{server})" @servers.delete(server) end end if @servers.count.zero? return false end return true end |