From e710ced6595f3f91fdb7635434ca7a5860672c41 Mon Sep 17 00:00:00 2001 From: akr Date: Wed, 15 Jun 2005 15:32:46 +0000 Subject: [PATCH] * lib/resolv.rb (Resolv::DNS::Resource#ttl): new attribute. (Resolv::DNS::Resource#==): ignore @ttl. (Resolv::DNS::Resource#hash): ditto. (Resolv::DNS::Message::MessageDecoder#get_rr): save TTL in a Resource object. based on [ruby-core:5190] by Eric Hodel. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8627 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 9 +++++++++ lib/resolv.rb | 29 ++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3429e3acf4..86fd544442 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Thu Jun 16 00:13:41 2005 Tanaka Akira + + * lib/resolv.rb (Resolv::DNS::Resource#ttl): new attribute. + (Resolv::DNS::Resource#==): ignore @ttl. + (Resolv::DNS::Resource#hash): ditto. + (Resolv::DNS::Message::MessageDecoder#get_rr): save TTL in a + Resource object. + based on [ruby-core:5190] by Eric Hodel. + Wed Jun 15 18:26:39 2005 Hidetoshi NAGAI * ext/tk/lib/tk.rb: support "tk inactive" sub-command [for Tcl/Tk8.5a3] diff --git a/lib/resolv.rb b/lib/resolv.rb index a57245b716..4f83560b8c 100644 --- a/lib/resolv.rb +++ b/lib/resolv.rb @@ -1406,7 +1406,9 @@ class Resolv name = self.get_name type, klass, ttl = self.get_unpack('nnN') typeclass = Resource.get_class(type, klass) - return name, ttl, self.get_length16 {typeclass.decode_rdata(self)} + res = self.get_length16 { typeclass.decode_rdata self } + res.instance_variable_set :@ttl, ttl + return name, ttl, res end end end @@ -1429,6 +1431,11 @@ class Resolv class Resource < Query + ## + # Remaining Time To Live for this Resource. + + attr_reader :ttl + ClassHash = {} # :nodoc: def encode_rdata(msg) # :nodoc: @@ -1440,10 +1447,16 @@ class Resolv end def ==(other) # :nodoc: - return self.class == other.class && - self.instance_variables == other.instance_variables && - self.instance_variables.collect {|name| self.instance_eval name} == - other.instance_variables.collect {|name| other.instance_eval name} + return false unless self.class == other.class + s_ivars = self.instance_variables + s_ivars.sort! + s_ivars.delete "@ttl" + o_ivars = other.instance_variables + o_ivars.sort! + o_ivars.delete "@ttl" + return s_ivars == o_ivars && + s_ivars.collect {|name| self.instance_variable_get name} == + o_ivars.collect {|name| other.instance_variable_get name} end def eql?(other) # :nodoc: @@ -1452,8 +1465,10 @@ class Resolv def hash # :nodoc: h = 0 - self.instance_variables.each {|name| - h ^= self.instance_eval("#{name}.hash") + vars = self.instance_variables + vars.delete "@ttl" + vars.each {|name| + h ^= self.instance_variable_get(name).hash } return h end