Class: MockDnsServer::History

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

Overview

Handles the history of events for this server.

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ History

Returns a new instance of History.



6
7
8
9
# File 'lib/mock_dns_server/history.rb', line 6

def initialize(context)
  @context = context
  @records = ThreadSafe::Array.new
end

Instance Method Details

#add(entry_hash) ⇒ Object



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

def add(entry_hash)
  entry_hash[:time] ||= Time.now
  @records << entry_hash
  entry_hash
end

#add_action_not_found(message) ⇒ Object



35
36
37
38
39
40
# File 'lib/mock_dns_server/history.rb', line 35

def add_action_not_found(message)
  add( {
    type: :action_not_found,
    message: message
  })
end

#add_conditional_action_removal(conditional_action) ⇒ Object



43
44
45
46
47
48
# File 'lib/mock_dns_server/history.rb', line 43

def add_conditional_action_removal(conditional_action)
  add( {
    type: :conditional_action_removal,
    conditional_action: conditional_action
  })
end

#add_incoming(message, sender, protocol, description = nil) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/mock_dns_server/history.rb', line 24

def add_incoming(message, sender, protocol, description = nil)
  add( {
    type: :incoming,
    message: message,
    sender: sender,
    protocol: protocol,
    description: description
  })
end

#add_notify_response(response, zts_host, zts_port, protocol) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/mock_dns_server/history.rb', line 51

def add_notify_response(response, zts_host, zts_port, protocol)
  add( {
      type: :notify_response,
      message: response,
      host: zts_host,
      port: zts_port,
      protocol: protocol,
      description: "notify response from #{zts_host}:#{zts_port}"
  })
end

#copyObject



74
75
76
# File 'lib/mock_dns_server/history.rb', line 74

def copy
  @records.map { |record| record.clone }
end

#occurred?(inspection) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/mock_dns_server/history.rb', line 63

def occurred?(inspection)
  HistoryInspections.new.apply(@records, inspection).size > 0
end

#sizeObject



12
13
14
# File 'lib/mock_dns_server/history.rb', line 12

def size
  @records.size
end

#to_aObject

Returns a clone of the array.

Returns:

  • a clone of the array



69
70
71
# File 'lib/mock_dns_server/history.rb', line 69

def to_a
  @records.clone
end

#to_sObject



79
80
81
# File 'lib/mock_dns_server/history.rb', line 79

def to_s
  "#{super}: #{@records}"
end