Class: MockDnsServer::History
- Inherits:
-
Object
- Object
- MockDnsServer::History
- Defined in:
- lib/mock_dns_server/history.rb
Overview
Handles the history of events for this server.
Instance Method Summary collapse
- #add(entry_hash) ⇒ Object
- #add_action_not_found(message) ⇒ Object
- #add_conditional_action_removal(conditional_action) ⇒ Object
- #add_incoming(message, sender, protocol, description = nil) ⇒ Object
- #add_notify_response(response, zts_host, zts_port, protocol) ⇒ Object
- #copy ⇒ Object
-
#initialize(context) ⇒ History
constructor
A new instance of History.
- #occurred?(inspection) ⇒ Boolean
- #size ⇒ Object
-
#to_a ⇒ Object
A clone of the array.
- #to_s ⇒ Object
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() add( { type: :action_not_found, 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(, sender, protocol, description = nil) add( { type: :incoming, 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 |
#copy ⇒ Object
74 75 76 |
# File 'lib/mock_dns_server/history.rb', line 74 def copy @records.map { |record| record.clone } end |
#occurred?(inspection) ⇒ Boolean
63 64 65 |
# File 'lib/mock_dns_server/history.rb', line 63 def occurred?(inspection) HistoryInspections.new.apply(@records, inspection).size > 0 end |
#size ⇒ Object
12 13 14 |
# File 'lib/mock_dns_server/history.rb', line 12 def size @records.size end |
#to_a ⇒ Object
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_s ⇒ Object
79 80 81 |
# File 'lib/mock_dns_server/history.rb', line 79 def to_s "#{super}: #{@records}" end |