Class: Net::DNS::Resolver::DnsTimeout

Inherits:
Object
  • Object
show all
Defined in:
lib/net/dns/resolver/timeouts.rb

Direct Known Subclasses

TcpTimeout, UdpTimeout

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(seconds) ⇒ DnsTimeout

Returns a new instance of DnsTimeout.

Raises:

  • (ArgumentError)


9
10
11
12
13
# File 'lib/net/dns/resolver/timeouts.rb', line 9

def initialize(seconds)
  raise ArgumentError, "Invalid value for tcp timeout" unless seconds.is_a?(Numeric) && seconds >= 0

  @seconds = seconds
end

Instance Attribute Details

#secondsObject (readonly)

Returns the value of attribute seconds.



7
8
9
# File 'lib/net/dns/resolver/timeouts.rb', line 7

def seconds
  @seconds
end

Instance Method Details

#pretty_to_sObject



21
22
23
# File 'lib/net/dns/resolver/timeouts.rb', line 21

def pretty_to_s
  transform(@seconds)
end

#timeout(&block) ⇒ Object

Executes the method’s block. If the block execution terminates before sec seconds has passed, it returns true. If not, it terminates the execution and raises Timeout::Error. If @seconds is 0 or nil, no timeout is set.

Raises:

  • (LocalJumpError)


29
30
31
32
33
# File 'lib/net/dns/resolver/timeouts.rb', line 29

def timeout(&block)
  raise LocalJumpError, "no block given" unless block_given?

  Timeout.timeout(@seconds, &block)
end

#to_sObject

Returns a string representation of the timeout corresponding to the number of @seconds.



17
18
19
# File 'lib/net/dns/resolver/timeouts.rb', line 17

def to_s
  @seconds == 0 ? @output.to_s : @seconds.to_s
end