From 830dae4ffd9eda3686494599152aab5515946799 Mon Sep 17 00:00:00 2001 From: Aaron Spettl Date: Thu, 23 Aug 2018 18:30:40 +0200 Subject: [PATCH] Dump zone $ORIGIN/$TTL if present --- lib/dns/zone.rb | 14 ++++++++++++-- test/zone_test.rb | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/dns/zone.rb b/lib/dns/zone.rb index 8e6fcee..6cad17d 100644 --- a/lib/dns/zone.rb +++ b/lib/dns/zone.rb @@ -59,7 +59,7 @@ def dump content << rr.dump end - content.join("\n") << "\n" + dump_directives << content.join("\n") << "\n" end # Generates pretty output of the zone and its records. @@ -75,7 +75,7 @@ def dump_pretty last_type = rr.type end - content.join("\n") << "\n" + dump_directives << content.join("\n") << "\n" end # Load the provided zone file data into a new DNS::Zone object. @@ -185,6 +185,16 @@ def self.extract_entries(string) private + # Dumps the $ORIGIN and $TTL directives of this zone (for use by #dump and #dump_pretty). + # + # @api private + def dump_directives + content = "" + content << "$ORIGIN #{origin}\n" unless origin.to_s.empty? + content << "$TTL #{ttl}\n" unless ttl.to_s.empty? + content + end + # Records sorted with more important types being at the top. # # @api private diff --git a/test/zone_test.rb b/test/zone_test.rb index f307ae8..83e2ce2 100644 --- a/test/zone_test.rb +++ b/test/zone_test.rb @@ -51,6 +51,7 @@ class ZoneTest < DNS::Zone::TestCase # basic zone file example ZONE_FILE_BASIC_EXAMPLE =<<-EOL +$ORIGIN lividpenguin.com. @ IN SOA ns0.lividpenguin.com. luke.lividpenguin.com. ( 2013101406 12h 15m 3w 3h ) @ IN NS ns0.lividpenguin.com. @ IN MX 10 mail