Class: Net::DNS::Resolver::DnsTimeout
- Inherits:
-
Object
- Object
- Net::DNS::Resolver::DnsTimeout
- Defined in:
- lib/net/dns/resolver/timeouts.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#seconds ⇒ Object
readonly
Returns the value of attribute seconds.
Instance Method Summary collapse
-
#initialize(seconds) ⇒ DnsTimeout
constructor
A new instance of DnsTimeout.
- #pretty_to_s ⇒ Object
-
#timeout(&block) ⇒ Object
Executes the method’s block.
-
#to_s ⇒ Object
Returns a string representation of the timeout corresponding to the number of
@seconds
.
Constructor Details
#initialize(seconds) ⇒ DnsTimeout
Returns a new instance of DnsTimeout.
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
#seconds ⇒ Object (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_s ⇒ Object
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.
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_s ⇒ Object
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 |