Class: Gem::Resolv::DNS::SvcParams

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rubygems/vendor/resolv/lib/resolv.rb

Overview

SvcParams for service binding RRs. [RFC9460]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = []) ⇒ SvcParams

Create a list of SvcParams with the given initial content.

params has to be an enumerable of SvcParams. If its content has SvcParams with the duplicate key, the one appears last takes precedence.



1732
1733
1734
1735
1736
1737
1738
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1732

def initialize(params = [])
  @params = {}

  params.each do |param|
    add param
  end
end

Class Method Details

.decode(msg) ⇒ Object

:nodoc:



1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1792

def self.decode(msg) # :nodoc:
  params = msg.get_list do
    key, = msg.get_unpack('n')
    msg.get_length16 do
      SvcParam::ClassHash[key].decode(msg)
    end
  end

  return self.new(params)
end

Instance Method Details

#[](key) ⇒ Object

Get SvcParam for the given key in this list.



1743
1744
1745
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1743

def [](key)
  @params[canonical_key(key)]
end

#add(param) ⇒ Object

Add the SvcParam param to this list, overwriting the existing one with the same key.



1764
1765
1766
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1764

def add(param)
  @params[param.class.key_number] = param
end

#countObject

Get the number of SvcParams in this list.



1750
1751
1752
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1750

def count
  @params.count
end

#delete(key) ⇒ Object

Remove the SvcParam with the given key and return it.



1771
1772
1773
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1771

def delete(key)
  @params.delete(canonical_key(key))
end

#each(&block) ⇒ Object

Enumerate the SvcParams in this list.



1778
1779
1780
1781
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1778

def each(&block)
  return enum_for(:each) unless block
  @params.each_value(&block)
end

#empty?Boolean

Get whether this list is empty.

Returns:

  • (Boolean)


1757
1758
1759
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1757

def empty?
  @params.empty?
end

#encode(msg) ⇒ Object

:nodoc:



1783
1784
1785
1786
1787
1788
1789
1790
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1783

def encode(msg) # :nodoc:
  @params.keys.sort.each do |key|
    msg.put_pack('n', key)
    msg.put_length16 do
      @params.fetch(key).encode(msg)
    end
  end
end