Class: Mongo::Srv::Result Private

Inherits:
Object
  • Object
show all
Includes:
Address::Validator
Defined in:
lib/mongo/srv/result.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

SRV record lookup result.

Contains server addresses that the query resolved to, and minimum TTL of the DNS records.

Constant Summary collapse

MISMATCHED_DOMAINNAME =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Returns MISMATCHED_DOMAINNAME Error message format string indicating that an SRV record found does not match the domain of a hostname.

Returns:

  • (String)

    MISMATCHED_DOMAINNAME Error message format string indicating that an SRV record found does not match the domain of a hostname.

"Parent domain name in SRV record result (%s) does not match " +
"that of the hostname (%s)".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Address::Validator

#validate_address_str!

Constructor Details

#initialize(hostname) ⇒ Result

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a new object to keep track of the SRV records of the hostname.

Parameters:

  • hostname (String)

    The hostname pointing to the DNS records.



49
50
51
52
53
# File 'lib/mongo/srv/result.rb', line 49

def initialize(hostname)
  @query_hostname = hostname
  @address_strs = []
  @min_ttl = nil
end

Instance Attribute Details

#address_strsArray<String> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns address_strs The host strings of the SRV records for the query hostname.

Returns:

  • (Array<String>)

    address_strs The host strings of the SRV records for the query hostname.



40
41
42
# File 'lib/mongo/srv/result.rb', line 40

def address_strs
  @address_strs
end

#min_ttlInteger | nil

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns min_ttl The smallest TTL found among the records (or nil if no records have been added).

Returns:

  • (Integer | nil)

    min_ttl The smallest TTL found among the records (or nil if no records have been added).



44
45
46
# File 'lib/mongo/srv/result.rb', line 44

def min_ttl
  @min_ttl
end

#query_hostnameString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns query_hostname The hostname pointing to the DNS records.

Returns:

  • (String)

    query_hostname The hostname pointing to the DNS records.



36
37
38
# File 'lib/mongo/srv/result.rb', line 36

def query_hostname
  @query_hostname
end

Instance Method Details

#add_record(record) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Adds a new record.

Parameters:

  • record (Resolv::DNS::Resource)

    An SRV record found for the hostname.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/mongo/srv/result.rb', line 65

def add_record(record)
  record_host = normalize_hostname(record.target.to_s)
  port = record.port
  validate_hostname!(record_host)
  validate_same_origin!(record_host)
  address_str = if record_host.index(':')
    # IPV6 address
    "[#{record_host}]:#{port}"
  else
    "#{record_host}:#{port}"
  end
  @address_strs << address_str

  if @min_ttl.nil?
    @min_ttl = record.ttl
  else
    @min_ttl = [@min_ttl, record.ttl].min
  end

  nil
end

#empty?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Checks whether there are any records.

Returns:

  • (Boolean)

    Whether or not there are any records.



58
59
60
# File 'lib/mongo/srv/result.rb', line 58

def empty?
  @address_strs.empty?
end