Class: MockDnsServer::ConditionalActionFactory
- Inherits:
-
Object
- Object
- MockDnsServer::ConditionalActionFactory
- Defined in:
- lib/mock_dns_server/conditional_action_factory.rb
Overview
Provides conditional actions that may be commonly used.
Instance Attribute Summary collapse
-
#action_factory ⇒ Object
readonly
Returns the value of attribute action_factory.
Instance Method Summary collapse
-
#echo ⇒ Object
Probably only used for testing, this ConditionalAction will unconditionally respond with the same object it receives.
-
#initialize ⇒ ConditionalActionFactory
constructor
A new instance of ConditionalActionFactory.
-
#soa_response(serial, zone, times = 0) ⇒ Object
Causes a SOA response with the specified serial to be sent upon receiving a SOA request.
- #specified_a_response(qname, answer_string, times = 0) ⇒ Object
-
#zone_load(serial_history, times = 0) ⇒ Object
Sets up the server to respond to SOA requests with the given SOA, and respond to AXFR requests with the specified data, wrapped in SOA responses.
Constructor Details
#initialize ⇒ ConditionalActionFactory
Returns a new instance of ConditionalActionFactory.
13 14 15 16 |
# File 'lib/mock_dns_server/conditional_action_factory.rb', line 13 def initialize @action_factory = ActionFactory.new @predicate_factory = PredicateFactory.new end |
Instance Attribute Details
#action_factory ⇒ Object (readonly)
Returns the value of attribute action_factory.
11 12 13 |
# File 'lib/mock_dns_server/conditional_action_factory.rb', line 11 def action_factory @action_factory end |
Instance Method Details
#echo ⇒ Object
Probably only used for testing, this ConditionalAction will unconditionally respond with the same object it receives.
21 22 23 |
# File 'lib/mock_dns_server/conditional_action_factory.rb', line 21 def echo ConditionalAction.new(PredicateFactory.new.always_true, action_factory.echo, 0) end |
#soa_response(serial, zone, times = 0) ⇒ Object
Causes a SOA response with the specified serial to be sent upon receiving a SOA request. If zone is specified, the action will only be performed if the request specifies that zone.
36 37 38 39 40 41 |
# File 'lib/mock_dns_server/conditional_action_factory.rb', line 36 def soa_response(serial, zone, times = 0) predicate = @predicate_factory.all(@predicate_factory.qname(zone), @predicate_factory.soa) response = MessageBuilder.soa_response(name: zone, serial: serial) action = @action_factory.(response) ConditionalAction.new(predicate, action, times) end |
#specified_a_response(qname, answer_string, times = 0) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/mock_dns_server/conditional_action_factory.rb', line 26 def specified_a_response(qname, answer_string, times = 0) predicate = @predicate_factory.a_request(qname) response = MessageBuilder.specified_a_response(answer_string) action = @action_factory.(response) ConditionalAction.new(predicate, action, times) end |
#zone_load(serial_history, times = 0) ⇒ Object
Sets up the server to respond to SOA requests with the given SOA, and respond to AXFR requests with the specified data, wrapped in SOA responses.
46 47 48 49 50 51 |
# File 'lib/mock_dns_server/conditional_action_factory.rb', line 46 def zone_load(serial_history, times = 0) pr = @predicate_factory predicate = pr.all(pr.qname(serial_history.zone), pr.zone_load) action = ActionFactory.new.zone_load(serial_history) ConditionalAction.new(predicate, action, times) end |