Class: MockDnsServer::SerialTransaction

Inherits:
Object
  • Object
show all
Defined in:
lib/mock_dns_server/serial_transaction.rb

Overview

Manages RR additions and deletions for a given serial.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zone, serial, deletions = [], additions = []) ⇒ SerialTransaction

An object containing serial change information

Parameters:

  • zone

    the zone for which this data applies

  • serial

    a number from 0 to 2^32 - 1, or a SerialNumber instance

  • deletions (defaults to: [])

    a single RR or an array of RR’s representing deletions

  • additions (defaults to: [])

    a single RR or an array of RR’s representing additions



17
18
19
20
21
22
# File 'lib/mock_dns_server/serial_transaction.rb', line 17

def initialize(zone, serial, deletions = [], additions = [])
  @zone = zone
  @serial = SerialNumber.object(serial)
  @deletions = Array(deletions)
  @additions = Array(additions)
end

Instance Attribute Details

#additionsObject

serial is the starting serial, i.e. the serial to which the additions and changes will be applied to get to the next serial value.



9
10
11
# File 'lib/mock_dns_server/serial_transaction.rb', line 9

def additions
  @additions
end

#deletionsObject

serial is the starting serial, i.e. the serial to which the additions and changes will be applied to get to the next serial value.



9
10
11
# File 'lib/mock_dns_server/serial_transaction.rb', line 9

def deletions
  @deletions
end

#serialObject

serial is the starting serial, i.e. the serial to which the additions and changes will be applied to get to the next serial value.



9
10
11
# File 'lib/mock_dns_server/serial_transaction.rb', line 9

def serial
  @serial
end

#zoneObject

serial is the starting serial, i.e. the serial to which the additions and changes will be applied to get to the next serial value.



9
10
11
# File 'lib/mock_dns_server/serial_transaction.rb', line 9

def zone
  @zone
end

Instance Method Details

#ixfr_records(start_serial) ⇒ Object

Returns an array of records corresponding to a serial change of 1, including delimiting SOA records, suitable for inclusion in an IXFR response.



28
29
30
31
32
33
34
35
36
# File 'lib/mock_dns_server/serial_transaction.rb', line 28

def ixfr_records(start_serial)
  records = []
  records << MessageBuilder.soa_answer(name: zone, serial: start_serial)
  deletions.each { |record| records << record }
  records << MessageBuilder.soa_answer(name: zone, serial: serial)
  additions.each { |record| records << record }
  #require 'awesome_print'; puts ''; ap records; puts ''
  records
end

#to_sObject



39
40
41
42
43
44
# File 'lib/mock_dns_server/serial_transaction.rb', line 39

def to_s
  s = "Changes to serial #{serial}:\n"
  deletions.each { |d| s << "- #{d}\n" }
  additions.each { |a| s << "+ #{a}\n" }
  s
end