123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, Enumerable
Inherits: Object
Defined in: lib/rubygems/vendor/resolv/lib/resolv.rb

Overview

SvcParams for service binding RRs. [RFC9460]

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(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.

[ GitHub ]

  
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1729

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

  params.each do |param|
    add param
  end
end

Class Method Details

.decode(msg)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1789

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 Attribute Details

#empty?Boolean (readonly)

Get whether this list is empty.

[ GitHub ]

  
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1754

def empty?
  @params.empty?
end

Instance Method Details

#[](key)

Get SvcParam for the given key in this list.

[ GitHub ]

  
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1740

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

#add(param)

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

[ GitHub ]

  
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1761

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

#canonical_key(key) (private)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1802

def canonical_key(key) # :nodoc:
  case key
  when Integer
    key
  when /\Akey(\d+)\z/
    Integer($1)
  when Symbol
    SvcParam::ClassHash[key].key_number
  else
    raise TypeError, 'key must be either String or Symbol'
  end
end

#count

Get the number of SvcParams in this list.

[ GitHub ]

  
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1747

def count
  @params.count
end

#delete(key)

Remove the SvcParam with the given key and return it.

[ GitHub ]

  
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1768

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

#each(&block)

Enumerate the SvcParams in this list.

[ GitHub ]

  
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1775

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

#encode(msg)

This method is for internal use only.
[ GitHub ]

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

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