Class: DNS::Zone::RR::Record Abstract
- Inherits:
-
Object
- Object
- DNS::Zone::RR::Record
- Defined in:
- lib/dns/zone/rr/record.rb
Overview
Direct Known Subclasses
A, CNAME, DNSKEY, DS, HINFO, MX, NAPTR, NS, NSEC, NSEC3, NSEC3PARAM, PTR, RRSIG, SOA, SRV, SSHFP, TXT
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#label ⇒ Object
Returns the value of attribute label.
-
#ttl ⇒ Object
Returns the value of attribute ttl.
Instance Method Summary collapse
-
#dump ⇒ String
Build RR zone file output.
-
#general_prefix ⇒ Array<String>
Returns ‘general’ prefix (in parts) that come before the RDATA.
-
#initialize ⇒ Record
constructor
A new instance of Record.
- #load(string, options = {}) ⇒ Object abstract
-
#load_general_and_get_rdata(string, options = {}) ⇒ String
Load ‘general’ RR data/params and return the remaining RDATA for further parsing.
-
#type ⇒ String
FIXME: should we just: ‘def type; ’SOA’; end` rather then do the class name convension?.
Constructor Details
#initialize ⇒ Record
Returns a new instance of Record.
10 11 12 13 |
# File 'lib/dns/zone/rr/record.rb', line 10 def initialize @label = '@' @klass = 'IN' end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
8 9 10 |
# File 'lib/dns/zone/rr/record.rb', line 8 def klass @klass end |
#label ⇒ Object
Returns the value of attribute label.
7 8 9 |
# File 'lib/dns/zone/rr/record.rb', line 7 def label @label end |
#ttl ⇒ Object
Returns the value of attribute ttl.
7 8 9 |
# File 'lib/dns/zone/rr/record.rb', line 7 def ttl @ttl end |
Instance Method Details
#dump ⇒ String
Build RR zone file output.
46 47 48 |
# File 'lib/dns/zone/rr/record.rb', line 46 def dump general_prefix.join(' ') end |
#general_prefix ⇒ Array<String>
Returns ‘general’ prefix (in parts) that come before the RDATA. Used by all RR types, generates: ‘[<label>] [<ttl>] [<class>] <type>`
34 35 36 37 38 39 40 41 |
# File 'lib/dns/zone/rr/record.rb', line 34 def general_prefix parts = [] parts << label parts << ttl if ttl parts << 'IN' parts << type parts end |
#load(string, options = {}) ⇒ Object
Override to update instance with RR type spesific data.
55 56 57 |
# File 'lib/dns/zone/rr/record.rb', line 55 def load(string, = {}) raise NotImplementedError, "#load method must be implemented by subclass (#{self.class})" end |
#load_general_and_get_rdata(string, options = {}) ⇒ String
Load ‘general’ RR data/params and return the remaining RDATA for further parsing.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/dns/zone/rr/record.rb', line 64 def load_general_and_get_rdata(string, = {}) # strip comments, unless its escaped. # skip semicolons within "quote segments" (TXT records) string.gsub!(/((?<!\\);)(?=(?:[^"]|"[^"]*")*$).*/o, "") captures = string.match(DNS::Zone::RR::REGEX_RR) return nil unless captures if [' ', nil].include?(captures[:label]) @label = [:last_label] else @label = captures[:label] end # unroll records nested under other origins unrolled_origin = [:last_origin].sub([:origin], '').chomp('.') if [:last_origin] if unrolled_origin && !unrolled_origin.empty? @label = @label == '@' ? unrolled_origin : "#{@label}.#{unrolled_origin}" end @ttl = captures[:ttl] captures[:rdata] end |
#type ⇒ String
FIXME: should we just: ‘def type; ’SOA’; end` rather then do the class name convension?
Figures out TYPE of RR using class name. This means the class name must match the RR ASCII TYPE.
When called directly on the parent class (that you should never do), it will
return the string as `<type>`, for use with internal tests.
24 25 26 27 28 |
# File 'lib/dns/zone/rr/record.rb', line 24 def type name = self.class.name.split('::').last return '<type>' if name == 'Record' name end |