On 10 Jun 2005, at 02:39, Eric Hodel wrote: > I would like to retrieve the TTL values from Resolv, but they seem > to get thrown away long before they're near the public API, and > digging through the guts of Resolv::DNS would only result in much > duplicate code. > > The following patch adds #ttl to Resolv::DNS::Resource. I also > changed #== and #hash because the TTL changes every time a new > resource is requested. Has anyone had a chance to review this patch? > Index: lib/resolv.rb > =================================================================== > RCS file: /src/ruby/lib/resolv.rb,v > retrieving revision 1.29 > diff -u -r1.29 resolv.rb > --- lib/resolv.rb 9 Jun 2005 22:47:35 -0000 1.29 > +++ lib/resolv.rb 10 Jun 2005 08:57:09 -0000 > @@ -1406,7 +1406,10 @@ > 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 +1432,11 @@ > > class Resource < Query > > + ## > + # Remaining Time To Live for this Resource. > + > + attr_reader :ttl > + > ClassHash = {} # :nodoc: > > def encode_rdata(msg) # :nodoc: > @@ -1440,10 +1448,13 @@ > 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.reject { |name| name == > "@ttl" } > + o_ivars = other.instance_variables.reject { |name| name == > "@ttl" } > + > + return s_ivars == o_ivars && > + s_ivars.collect {|name| self.instance_eval name} == > + o_ivars.collect {|name| other.instance_eval name} > end > > def eql?(other) # :nodoc: > @@ -1452,7 +1463,7 @@ > > def hash # :nodoc: > h = 0 > - self.instance_variables.each {|name| > + self.instance_variables.reject { |name| name == > "@ttl" }.each {|name| > h ^= self.instance_eval("#{name}.hash") > } > return h > > > -- Eric Hodel - drbrain / segment7.net - http://segment7.net FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04