Class: MockDnsServer::MessageTransformer
- Inherits:
-
Object
- Object
- MockDnsServer::MessageTransformer
- Defined in:
- lib/mock_dns_server/message_transformer.rb
Overview
Lambdas that transform a message into something else, usually a message component such as domain or qtype.
Instance Attribute Summary collapse
-
#message ⇒ Object
Returns the value of attribute message.
Instance Method Summary collapse
- #answer_count(answer_type) ⇒ Object
- #first_question ⇒ Object
-
#initialize(dns_message) ⇒ MessageTransformer
constructor
Initialize the transformer with a message.
-
#qclass ⇒ Object
The message’s qclass as a String.
-
#qname ⇒ Object
The message’s qname as a String.
-
#qtype ⇒ Object
The message’s qtype as a String.
- #question_attr(symbol) ⇒ Object
-
#serial(location = :answer) ⇒ Object
A SOA record is usually in the answer section, but in the case of IXFR requests it will be in the authority section.
Constructor Details
#initialize(dns_message) ⇒ MessageTransformer
Initialize the transformer with a message.
10 11 12 |
# File 'lib/mock_dns_server/message_transformer.rb', line 10 def initialize() self. = end |
Instance Attribute Details
#message ⇒ Object
Returns the value of attribute message.
6 7 8 |
# File 'lib/mock_dns_server/message_transformer.rb', line 6 def @message end |
Instance Method Details
#answer_count(answer_type) ⇒ Object
70 71 72 |
# File 'lib/mock_dns_server/message_transformer.rb', line 70 def answer_count(answer_type) .answer.select { |a| a.rr_type.to_s == answer_type}.count end |
#first_question ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/mock_dns_server/message_transformer.rb', line 60 def first_question has_question = && .question && .question.first && .question.first.is_a?(Dnsruby::Question) has_question ? .question.first : nil end |
#qclass ⇒ Object
Returns the message’s qclass as a String.
49 50 51 |
# File 'lib/mock_dns_server/message_transformer.rb', line 49 def qclass question_attr(:qclass) end |
#qname ⇒ Object
Returns the message’s qname as a String.
43 44 45 |
# File 'lib/mock_dns_server/message_transformer.rb', line 43 def qname question_attr(:qname) end |
#qtype ⇒ Object
Returns the message’s qtype as a String.
36 37 38 39 |
# File 'lib/mock_dns_server/message_transformer.rb', line 36 def qtype dnsruby_type_instance = question_attr(:qtype) Dnsruby::Types.to_string(dnsruby_type_instance) end |
#question_attr(symbol) ⇒ Object
54 55 56 57 |
# File 'lib/mock_dns_server/message_transformer.rb', line 54 def question_attr(symbol) question = first_question question ? question.send(symbol).to_s : nil end |
#serial(location = :answer) ⇒ Object
A SOA record is usually in the answer section, but in the case of IXFR requests it will be in the authority section.
24 25 26 27 28 29 30 31 32 |
# File 'lib/mock_dns_server/message_transformer.rb', line 24 def serial(location = :answer) return nil if .nil? target_section = .send(location == :answer ? :answer : :authority) return nil if target_section.nil? soa_answer = target_section.detect { |record| record.is_a?(Dnsruby::RR::IN::SOA) } soa_answer ? soa_answer.serial : nil end |