net-dns 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +6 -14
  2. data/.gitignore +1 -1
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +3 -0
  5. data/.rubocop_defaults.yml +364 -0
  6. data/.rubocop_todo.yml +207 -0
  7. data/.travis.yml +9 -16
  8. data/CHANGELOG.md +12 -1
  9. data/Gemfile +6 -2
  10. data/LICENSE.txt +56 -0
  11. data/README.md +94 -77
  12. data/Rakefile +23 -56
  13. data/bin/console +14 -0
  14. data/demo/check_soa.rb +27 -38
  15. data/demo/threads.rb +3 -7
  16. data/lib/net/dns.rb +4 -11
  17. data/lib/net/dns/core_ext.rb +8 -15
  18. data/lib/net/dns/header.rb +58 -66
  19. data/lib/net/dns/names.rb +25 -23
  20. data/lib/net/dns/packet.rb +136 -139
  21. data/lib/net/dns/question.rb +36 -39
  22. data/lib/net/dns/resolver.rb +103 -113
  23. data/lib/net/dns/resolver/socks.rb +45 -51
  24. data/lib/net/dns/resolver/timeouts.rb +17 -26
  25. data/lib/net/dns/rr.rb +107 -117
  26. data/lib/net/dns/rr/a.rb +46 -55
  27. data/lib/net/dns/rr/aaaa.rb +40 -49
  28. data/lib/net/dns/rr/classes.rb +26 -29
  29. data/lib/net/dns/rr/cname.rb +33 -41
  30. data/lib/net/dns/rr/hinfo.rb +44 -56
  31. data/lib/net/dns/rr/mr.rb +33 -42
  32. data/lib/net/dns/rr/mx.rb +37 -47
  33. data/lib/net/dns/rr/ns.rb +33 -41
  34. data/lib/net/dns/rr/null.rb +8 -11
  35. data/lib/net/dns/rr/ptr.rb +14 -20
  36. data/lib/net/dns/rr/soa.rb +27 -30
  37. data/lib/net/dns/rr/srv.rb +13 -17
  38. data/lib/net/dns/rr/txt.rb +8 -11
  39. data/lib/net/dns/rr/types.rb +97 -99
  40. data/lib/net/dns/version.rb +5 -13
  41. data/net-dns.gemspec +17 -29
  42. data/{fixtures → spec/fixtures}/resolv.conf +0 -0
  43. data/spec/spec_helper.rb +14 -0
  44. data/spec/unit/resolver/dns_timeout_spec.rb +36 -0
  45. data/spec/unit/resolver/tcp_timeout_spec.rb +46 -0
  46. data/spec/unit/resolver/udp_timeout_spec.rb +46 -0
  47. data/test/test_helper.rb +12 -3
  48. data/test/{header_test.rb → unit/header_test.rb} +43 -46
  49. data/test/{names_test.rb → unit/names_test.rb} +1 -1
  50. data/test/{packet_test.rb → unit/packet_test.rb} +3 -5
  51. data/test/{question_test.rb → unit/question_test.rb} +3 -5
  52. data/test/{resolver_test.rb → unit/resolver_test.rb} +10 -13
  53. data/test/{rr → unit/rr}/a_test.rb +10 -17
  54. data/test/{rr → unit/rr}/aaaa_test.rb +7 -14
  55. data/test/{rr → unit/rr}/classes_test.rb +14 -16
  56. data/test/{rr → unit/rr}/cname_test.rb +7 -14
  57. data/test/{rr → unit/rr}/hinfo_test.rb +16 -22
  58. data/test/{rr → unit/rr}/mr_test.rb +12 -18
  59. data/test/{rr → unit/rr}/mx_test.rb +18 -24
  60. data/test/{rr → unit/rr}/ns_test.rb +10 -16
  61. data/test/{rr → unit/rr}/types_test.rb +10 -8
  62. data/test/{rr_test.rb → unit/rr_test.rb} +33 -37
  63. metadata +77 -49
  64. data/test/resolver/timeouts_test.rb +0 -109
@@ -1,7 +1,6 @@
1
1
  module Net # :nodoc:
2
2
  module DNS
3
3
  class RR
4
-
5
4
  #------------------------------------------------------------
6
5
  # RR type NULL
7
6
  #------------------------------------------------------------
@@ -20,11 +19,11 @@ module Net # :nodoc:
20
19
  end
21
20
 
22
21
  def get_inspect
23
- "#@null"
22
+ @null.to_s
24
23
  end
25
24
 
26
25
  def subclass_new_from_hash(args)
27
- if args.has_key? :null
26
+ if args.key? :null
28
27
  @null = args[:null]
29
28
  else
30
29
  raise ArgumentError, ":null field is mandatory but missing"
@@ -35,19 +34,17 @@ module Net # :nodoc:
35
34
  @null = str.strip
36
35
  end
37
36
 
38
- def subclass_new_from_binary(data,offset)
39
- @null = data[offset..offset+@rdlength]
40
- return offset + @rdlength
37
+ def subclass_new_from_binary(data, offset)
38
+ @null = data[offset..offset + @rdlength]
39
+ offset + @rdlength
41
40
  end
42
41
 
43
42
  private
44
43
 
45
- def set_type
46
- @type = Net::DNS::RR::Types.new("NULL")
47
- end
48
-
44
+ def set_type
45
+ @type = Net::DNS::RR::Types.new("NULL")
46
+ end
49
47
  end
50
-
51
48
  end
52
49
  end
53
50
  end
@@ -1,18 +1,16 @@
1
1
  module Net
2
2
  module DNS
3
3
  class RR
4
-
5
4
  #
6
5
  # = Pointer Record (PTR)
7
6
  #
8
7
  # Class for DNS Pointer (PTR) resource records.
9
8
  #
10
- # Pointer records are the opposite of A and AAAA RRs
9
+ # Pointer records are the opposite of A and AAAA RRs
11
10
  # and are used in Reverse Map zone files to map
12
11
  # an IP address (IPv4 or IPv6) to a host name.
13
12
  #
14
13
  class PTR < RR
15
-
16
14
  # Gets the PTR value.
17
15
  #
18
16
  # Returns a String.
@@ -20,7 +18,7 @@ module Net
20
18
  @ptrdname.to_s
21
19
  end
22
20
 
23
- alias_method :ptr, :ptrdname
21
+ alias ptr ptrdname
24
22
 
25
23
  # Gets the standardized value for this record,
26
24
  # represented by the value of <tt>ptrdname</tt>.
@@ -30,7 +28,6 @@ module Net
30
28
  ptrdname.to_s
31
29
  end
32
30
 
33
-
34
31
  private
35
32
 
36
33
  def build_pack
@@ -43,7 +40,7 @@ module Net
43
40
  end
44
41
 
45
42
  def subclass_new_from_hash(args)
46
- if args.has_key?(:ptrdname) or args.has_key?(:ptr)
43
+ if args.key?(:ptrdname) || args.key?(:ptr)
47
44
  @ptrdname = args[:ptrdname]
48
45
  else
49
46
  raise ArgumentError, ":ptrdname or :ptr field is mandatory"
@@ -61,23 +58,20 @@ module Net
61
58
 
62
59
  private
63
60
 
64
- def set_type
65
- @type = Net::DNS::RR::Types.new("PTR")
66
- end
67
-
68
- def get_inspect
69
- value
70
- end
71
-
61
+ def set_type
62
+ @type = Net::DNS::RR::Types.new("PTR")
63
+ end
72
64
 
73
- def check_name(input)
74
- IPAddr.new(str)
75
- rescue
76
- raise ArgumentError, "Invalid PTR Section `#{input}'"
77
- end
65
+ def get_inspect
66
+ value
67
+ end
78
68
 
69
+ def check_name(input)
70
+ IPAddr.new(str)
71
+ rescue StandardError
72
+ raise ArgumentError, "Invalid PTR Section `#{input}'"
73
+ end
79
74
  end
80
-
81
75
  end
82
76
  end
83
77
  end
@@ -1,19 +1,18 @@
1
1
  module Net # :nodoc:
2
2
  module DNS
3
3
  class RR
4
-
5
4
  #------------------------------------------------------------
6
5
  # RR type SOA
7
6
  #------------------------------------------------------------
8
7
  class SOA < RR
9
8
  attr_reader :mname, :rname, :serial, :refresh, :retry, :expire, :minimum
10
-
9
+
11
10
  private
12
-
11
+
13
12
  def build_pack
14
13
  @soa_pack = pack_name(@mname)
15
14
  @soa_pack += pack_name(@rname)
16
- @soa_pack += [@serial,@refresh,@retry,@expire,@minimum].pack("N5")
15
+ @soa_pack += [@serial, @refresh, @retry, @expire, @minimum].pack("N5")
17
16
  end
18
17
 
19
18
  def get_data
@@ -21,28 +20,28 @@ module Net # :nodoc:
21
20
  end
22
21
 
23
22
  def get_inspect
24
- "#@mname #@rname #@serial #@refresh #@retry #@expire #@minimum"
23
+ "#{@mname} #{@rname} #{@serial} #{@refresh} #{@retry} #{@expire} #{@minimum}"
25
24
  end
26
25
 
27
26
  def subclass_new_from_hash(args)
28
- if args.has_key? :rdata
27
+ if args.key? :rdata
29
28
  subclass_new_from_string(args[:rdata])
30
29
  else
31
- [:mname,:rname,:serial,:refresh,:retry,:expire,:minimum].each do |key|
32
- raise ArgumentError, "Missing field :#{key}" unless args.has_key? key
30
+ %i[mname rname serial refresh retry expire minimum].each do |key|
31
+ raise ArgumentError, "Missing field :#{key}" unless args.key? key
33
32
  end
34
- @mname = args[:mname] if valid? args[:mname]
33
+ @mname = args[:mname] if valid? args[:mname]
35
34
  @rname = args[:rname] if valid? args[:rname]
36
- @serial = args[:serial] if number? args[:serial]
37
- @refresh = args[:refresh] if number? args[:refresh]
38
- @retry = args[:retry] if number? args[:retry]
39
- @expire = args[:expire] if number? args[:expire]
40
- @minimum = args[:minimum] if number? args[:minimum]
35
+ @serial = args[:serial] if number? args[:serial]
36
+ @refresh = args[:refresh] if number? args[:refresh]
37
+ @retry = args[:retry] if number? args[:retry]
38
+ @expire = args[:expire] if number? args[:expire]
39
+ @minimum = args[:minimum] if number? args[:minimum]
41
40
  end
42
41
  end
43
-
42
+
44
43
  def number?(num)
45
- if num.kind_of? Integer and num > 0
44
+ if num.is_a?(Integer) && (num > 0)
46
45
  true
47
46
  else
48
47
  raise ArgumentError, "Wrong format field: #{num} not a number or less than zero"
@@ -50,29 +49,27 @@ module Net # :nodoc:
50
49
  end
51
50
 
52
51
  def subclass_new_from_string(str)
53
- mname,rname,serial,refresh,ret,expire,minimum = str.strip.split(" ")
52
+ mname, rname, serial, refresh, ret, expire, minimum = str.strip.split(" ")
54
53
  @mname = mname if valid? mname
55
54
  @rname = rname if valid? rname
56
- @serial,@refresh,@retry,@expire,@minimum = [serial,refresh,ret,expire,minimum].collect do |i|
55
+ @serial, @refresh, @retry, @expire, @minimum = [serial, refresh, ret, expire, minimum].collect do |i|
57
56
  i.to_i if valid? i.to_i
58
57
  end
59
58
  end
60
59
 
61
- def subclass_new_from_binary(data,offset)
62
- @mname,offset = dn_expand(data,offset)
63
- @rname,offset = dn_expand(data,offset)
64
- @serial,@refresh,@retry,@expire,@minimum = data.unpack("@#{offset} N5")
65
- return offset + 5*Net::DNS::INT32SZ
60
+ def subclass_new_from_binary(data, offset)
61
+ @mname, offset = dn_expand(data, offset)
62
+ @rname, offset = dn_expand(data, offset)
63
+ @serial, @refresh, @retry, @expire, @minimum = data.unpack("@#{offset} N5")
64
+ offset + 5 * Net::DNS::INT32SZ
66
65
  end
67
-
66
+
68
67
  private
69
-
70
- def set_type
71
- @type = Net::DNS::RR::Types.new("SOA")
72
- end
73
-
68
+
69
+ def set_type
70
+ @type = Net::DNS::RR::Types.new("SOA")
71
+ end
74
72
  end
75
-
76
73
  end
77
74
  end
78
75
  end
@@ -1,45 +1,41 @@
1
1
  module Net # :nodoc:
2
2
  module DNS
3
3
  class RR
4
-
5
4
  #------------------------------------------------------------
6
5
  # RR type SRV
7
6
  #------------------------------------------------------------
8
7
  class SRV < RR
9
-
10
8
  attr_reader :priority, :weight, :port, :host
11
-
9
+
12
10
  private
13
-
11
+
14
12
  def build_pack
15
13
  str = ""
16
14
  end
17
-
18
- def subclass_new_from_binary(data,offset)
15
+
16
+ def subclass_new_from_binary(data, offset)
19
17
  off_end = offset + @rdlength
20
18
  @priority, @weight, @port = data.unpack("@#{offset} n n n")
21
- offset+=6
19
+ offset += 6
22
20
 
23
- @host=[]
21
+ @host = []
24
22
  while offset < off_end
25
23
  len = data.unpack("@#{offset} C")[0]
26
24
  offset += 1
27
- str = data[offset..offset+len-1]
25
+ str = data[offset..offset + len - 1]
28
26
  offset += len
29
27
  @host << str
30
28
  end
31
- @host=@host.join(".")
29
+ @host = @host.join(".")
32
30
  offset
33
31
  end
34
-
32
+
35
33
  private
36
-
37
- def set_type
38
- @type = Net::DNS::RR::Types.new("SRV")
39
- end
40
-
34
+
35
+ def set_type
36
+ @type = Net::DNS::RR::Types.new("SRV")
37
+ end
41
38
  end
42
39
  end
43
-
44
40
  end
45
41
  end
@@ -1,7 +1,6 @@
1
1
  module Net # :nodoc:
2
2
  module DNS
3
3
  class RR
4
-
5
4
  #------------------------------------------------------------
6
5
  # RR type TXT
7
6
  #------------------------------------------------------------
@@ -13,7 +12,7 @@ module Net # :nodoc:
13
12
  def build_pack
14
13
  str = ""
15
14
  @txt.split(" ").each do |txt|
16
- str += [txt.length,txt].pack("C a*")
15
+ str += [txt.length, txt].pack("C a*")
17
16
  end
18
17
  @txt_pack = str
19
18
  @rdlength = @txt_pack.size
@@ -24,7 +23,7 @@ module Net # :nodoc:
24
23
  end
25
24
 
26
25
  def subclass_new_from_hash(args)
27
- if args.has_key? :txt
26
+ if args.key? :txt
28
27
  @txt = args[:txt].strip
29
28
  else
30
29
  raise ArgumentError, ":txt field is mandatory but missing"
@@ -35,27 +34,25 @@ module Net # :nodoc:
35
34
  @txt = str.strip
36
35
  end
37
36
 
38
- def subclass_new_from_binary(data,offset)
37
+ def subclass_new_from_binary(data, offset)
39
38
  off_end = offset + @rdlength
40
39
  @txt = ""
41
40
  while offset < off_end
42
41
  len = data.unpack("@#{offset} C")[0]
43
42
  offset += 1
44
- str = data[offset..offset+len-1]
43
+ str = data[offset..offset + len - 1]
45
44
  offset += len
46
45
  @txt << str << " "
47
46
  end
48
- return offset
47
+ offset
49
48
  end
50
49
 
51
50
  private
52
51
 
53
- def set_type
54
- @type = Net::DNS::RR::Types.new("TXT")
55
- end
56
-
52
+ def set_type
53
+ @type = Net::DNS::RR::Types.new("TXT")
54
+ end
57
55
  end
58
-
59
56
  end
60
57
  end
61
58
  end
@@ -1,80 +1,81 @@
1
1
  module Net # :nodoc:
2
2
  module DNS
3
-
4
3
  class RR
5
-
6
4
  # This is an auxiliary class to handle RR type field in a DNS packet.
7
5
  class Types
8
-
9
6
  TYPES = {
10
- 'SIGZERO' => 0, # RFC2931 consider this a pseudo type
11
- 'A' => 1, # RFC 1035, Section 3.4.1
12
- 'NS' => 2, # RFC 1035, Section 3.3.11
13
- 'MD' => 3, # RFC 1035, Section 3.3.4 (obsolete)
14
- 'MF' => 4, # RFC 1035, Section 3.3.5 (obsolete)
15
- 'CNAME' => 5, # RFC 1035, Section 3.3.1
16
- 'SOA' => 6, # RFC 1035, Section 3.3.13
17
- 'MB' => 7, # RFC 1035, Section 3.3.3
18
- 'MG' => 8, # RFC 1035, Section 3.3.6
19
- 'MR' => 9, # RFC 1035, Section 3.3.8
20
- 'NULL' => 10, # RFC 1035, Section 3.3.10
21
- 'WKS' => 11, # RFC 1035, Section 3.4.2 (deprecated)
22
- 'PTR' => 12, # RFC 1035, Section 3.3.12
23
- 'HINFO' => 13, # RFC 1035, Section 3.3.2
24
- 'MINFO' => 14, # RFC 1035, Section 3.3.7
25
- 'MX' => 15, # RFC 1035, Section 3.3.9
26
- 'TXT' => 16, # RFC 1035, Section 3.3.14
27
- 'RP' => 17, # RFC 1183, Section 2.2
28
- 'AFSDB' => 18, # RFC 1183, Section 1
29
- 'X25' => 19, # RFC 1183, Section 3.1
30
- 'ISDN' => 20, # RFC 1183, Section 3.2
31
- 'RT' => 21, # RFC 1183, Section 3.3
32
- 'NSAP' => 22, # RFC 1706, Section 5
33
- 'NSAP_PTR' => 23, # RFC 1348 (obsolete)
7
+ 'SIGZERO' => 0, # RFC2931 consider this a pseudo type
8
+ 'A' => 1, # RFC 1035, Section 3.4.1
9
+ 'NS' => 2, # RFC 1035, Section 3.3.11
10
+ 'MD' => 3, # RFC 1035, Section 3.3.4 (obsolete)
11
+ 'MF' => 4, # RFC 1035, Section 3.3.5 (obsolete)
12
+ 'CNAME' => 5, # RFC 1035, Section 3.3.1
13
+ 'SOA' => 6, # RFC 1035, Section 3.3.13
14
+ 'MB' => 7, # RFC 1035, Section 3.3.3
15
+ 'MG' => 8, # RFC 1035, Section 3.3.6
16
+ 'MR' => 9, # RFC 1035, Section 3.3.8
17
+ 'NULL' => 10, # RFC 1035, Section 3.3.10
18
+ 'WKS' => 11, # RFC 1035, Section 3.4.2 (deprecated)
19
+ 'PTR' => 12, # RFC 1035, Section 3.3.12
20
+ 'HINFO' => 13, # RFC 1035, Section 3.3.2
21
+ 'MINFO' => 14, # RFC 1035, Section 3.3.7
22
+ 'MX' => 15, # RFC 1035, Section 3.3.9
23
+ 'TXT' => 16, # RFC 1035, Section 3.3.14
24
+ 'RP' => 17, # RFC 1183, Section 2.2
25
+ 'AFSDB' => 18, # RFC 1183, Section 1
26
+ 'X25' => 19, # RFC 1183, Section 3.1
27
+ 'ISDN' => 20, # RFC 1183, Section 3.2
28
+ 'RT' => 21, # RFC 1183, Section 3.3
29
+ 'NSAP' => 22, # RFC 1706, Section 5
30
+ 'NSAP_PTR' => 23, # RFC 1348 (obsolete)
34
31
  # The following 2 RRs are impemented in Net::DNS::SEC, TODO
35
- 'SIG' => 24, # RFC 2535, Section 4.1
36
- 'KEY' => 25, # RFC 2535, Section 3.1
37
- 'PX' => 26, # RFC 2163,
38
- 'GPOS' => 27, # RFC 1712 (obsolete)
39
- 'AAAA' => 28, # RFC 1886, Section 2.1
40
- 'LOC' => 29, # RFC 1876
32
+ 'SIG' => 24, # RFC 2535, Section 4.1
33
+ 'KEY' => 25, # RFC 2535, Section 3.1
34
+ 'PX' => 26, # RFC 2163,
35
+ 'GPOS' => 27, # RFC 1712 (obsolete)
36
+ 'AAAA' => 28, # RFC 1886, Section 2.1
37
+ 'LOC' => 29, # RFC 1876
41
38
  # The following RR is implemented in Net::DNS::SEC, TODO
42
- 'NXT' => 30, # RFC 2535, Section 5.2
43
- 'EID' => 31, # draft-ietf-nimrod-dns-xx.txt
44
- 'NIMLOC' => 32, # draft-ietf-nimrod-dns-xx.txt
45
- 'SRV' => 33, # RFC 2052
46
- 'ATMA' => 34, # ???
47
- 'NAPTR' => 35, # RFC 2168
48
- 'KX' => 36, # RFC 2230
49
- 'CERT' => 37, # RFC 2538
50
- 'DNAME' => 39, # RFC 2672
51
- 'OPT' => 41, # RFC 2671
39
+ 'NXT' => 30, # RFC 2535, Section 5.2
40
+ 'EID' => 31, # draft-ietf-nimrod-dns-xx.txt
41
+ 'NIMLOC' => 32, # draft-ietf-nimrod-dns-xx.txt
42
+ 'SRV' => 33, # RFC 2052
43
+ 'ATMA' => 34, # ???
44
+ 'NAPTR' => 35, # RFC 2168
45
+ 'KX' => 36, # RFC 2230
46
+ 'CERT' => 37, # RFC 2538
47
+ 'DNAME' => 39, # RFC 2672
48
+ 'OPT' => 41, # RFC 2671
52
49
  # The following 4 RRs are implemented in Net::DNS::SEC TODO
53
- 'DS' => 43, # draft-ietf-dnsext-delegation-signer
54
- 'SSHFP' => 44, # draft-ietf-secsh-dns (No RFC # yet at time of coding)
55
- 'RRSIG' => 46, # draft-ietf-dnsext-dnssec-2535typecode-change
56
- 'NSEC' => 47, # draft-ietf-dnsext-dnssec-2535typecode-change
57
- 'DNSKEY' => 48, # draft-ietf-dnsext-dnssec-2535typecode-change
58
- 'UINFO' => 100, # non-standard
59
- 'UID' => 101, # non-standard
60
- 'GID' => 102, # non-standard
61
- 'UNSPEC' => 103, # non-standard
62
- 'TKEY' => 249, # RFC 2930
63
- 'TSIG' => 250, # RFC 2931
64
- 'IXFR' => 251, # RFC 1995
65
- 'AXFR' => 252, # RFC 1035
66
- 'MAILB' => 253, # RFC 1035 (MB, MG, MR)
67
- 'MAILA' => 254, # RFC 1035 (obsolete - see MX)
68
- 'ANY' => 255, # RFC 1035
69
- }
50
+ 'DS' => 43, # draft-ietf-dnsext-delegation-signer
51
+ 'SSHFP' => 44, # draft-ietf-secsh-dns (No RFC # yet at time of coding)
52
+ 'RRSIG' => 46, # draft-ietf-dnsext-dnssec-2535typecode-change
53
+ 'NSEC' => 47, # draft-ietf-dnsext-dnssec-2535typecode-change
54
+ 'DNSKEY' => 48, # draft-ietf-dnsext-dnssec-2535typecode-change
55
+ 'UINFO' => 100, # non-standard
56
+ 'UID' => 101, # non-standard
57
+ 'GID' => 102, # non-standard
58
+ 'UNSPEC' => 103, # non-standard
59
+ 'TKEY' => 249, # RFC 2930
60
+ 'TSIG' => 250, # RFC 2931
61
+ 'IXFR' => 251, # RFC 1995
62
+ 'AXFR' => 252, # RFC 1035
63
+ 'MAILB' => 253, # RFC 1035 (MB, MG, MR)
64
+ 'MAILA' => 254, # RFC 1035 (obsolete - see MX)
65
+ 'ANY' => 255, # RFC 1035
66
+ }.freeze
70
67
 
71
68
  # The default value when type is nil in Resource Records
72
69
  @@default = TYPES["A"]
73
70
 
71
+ def self.default
72
+ @@default
73
+ end
74
+
74
75
  # Be able to control the default type to assign when
75
76
  # type is +nil+. Default to +A+
76
77
  def self.default=(str)
77
- if TYPES.has_key? str
78
+ if TYPES.key? str
78
79
  @@default = TYPES[str]
79
80
  else
80
81
  raise ArgumentError, "Unknown type #{str}"
@@ -84,12 +85,12 @@ module Net # :nodoc:
84
85
  # Checks whether +type+ is a valid RR type.
85
86
  def self.valid?(type)
86
87
  case type
87
- when String
88
- TYPES.has_key?(type)
89
- when Fixnum
90
- TYPES.invert.has_key?(type)
91
- else
92
- raise ArgumentError, "Wrong type class: #{type.class}"
88
+ when String
89
+ TYPES.key?(type)
90
+ when Integer
91
+ TYPES.invert.key?(type)
92
+ else
93
+ raise ArgumentError, "Wrong type class: #{type.class}"
93
94
  end
94
95
  end
95
96
 
@@ -97,14 +98,14 @@ module Net # :nodoc:
97
98
  # given the numeric value
98
99
  def self.to_str(type)
99
100
  case type
100
- when Fixnum
101
- if TYPES.invert.has_key? type
102
- TYPES.invert[type]
103
- else
104
- raise ArgumentError, "Unknown type number #{type}"
105
- end
101
+ when Integer
102
+ if TYPES.invert.key? type
103
+ TYPES.invert[type]
106
104
  else
107
- raise ArgumentError, "Wrong type class: #{type.class}"
105
+ raise ArgumentError, "Unknown type number #{type}"
106
+ end
107
+ else
108
+ raise ArgumentError, "Wrong type class: #{type.class}"
108
109
  end
109
110
  end
110
111
 
@@ -112,7 +113,7 @@ module Net # :nodoc:
112
113
  # in a format suited for regexps
113
114
  def self.regexp
114
115
  # Longest ones go first, so the regex engine will match AAAA before A.
115
- TYPES.keys.sort { |a,b| b.length <=> a.length }.join("|")
116
+ TYPES.keys.sort { |a, b| b.length <=> a.length }.join("|")
116
117
  end
117
118
 
118
119
  # Creates a new object representing an RR type. Performs some
@@ -123,7 +124,7 @@ module Net # :nodoc:
123
124
  when String
124
125
  # type in the form "A" or "NS"
125
126
  new_from_string(type.upcase)
126
- when Fixnum
127
+ when Integer
127
128
  # type in numeric form
128
129
  new_from_num(type)
129
130
  when nil
@@ -157,37 +158,34 @@ module Net # :nodoc:
157
158
  @num.to_s
158
159
  end
159
160
 
160
-
161
161
  private
162
162
 
163
- # Constructor for string data type.
164
- def new_from_string(type)
165
- case type
166
- when /^TYPE\\d+/
167
- # TODO!!!
163
+ # Constructor for string data type.
164
+ def new_from_string(type)
165
+ case type
166
+ when /^TYPE\\d+/
167
+ # TODO!!!
168
+ else
169
+ # String with name of type
170
+ if TYPES.key? type
171
+ @str = type
172
+ @num = TYPES[type]
168
173
  else
169
- # String with name of type
170
- if TYPES.has_key? type
171
- @str = type
172
- @num = TYPES[type]
173
- else
174
- raise ArgumentError, "Unknown type #{type}"
175
- end
174
+ raise ArgumentError, "Unknown type #{type}"
176
175
  end
177
176
  end
177
+ end
178
178
 
179
- # Contructor for numeric data type.
180
- def new_from_num(type)
181
- if TYPES.invert.has_key? type
182
- @num = type
183
- @str = TYPES.invert[type]
184
- else
185
- raise ArgumentError, "Unkown type number #{type}"
186
- end
179
+ # Contructor for numeric data type.
180
+ def new_from_num(type)
181
+ if TYPES.invert.key? type
182
+ @num = type
183
+ @str = TYPES.invert[type]
184
+ else
185
+ raise ArgumentError, "Unkown type number #{type}"
187
186
  end
188
-
187
+ end
189
188
  end
190
-
191
189
  end
192
190
  end
193
191
  end