Class: Gcloud::Dns::Importer
- Inherits:
-
Object
- Object
- Gcloud::Dns::Importer
- Defined in:
- lib/gcloud/dns/importer.rb
Overview
DNS Importer
Reads a DNS zone file and parses it, creating a collection of Record instances. The returned records are unsaved, as they are not yet associated with a Zone. Use Zone#import to add zone file records to a Zone.
Because the Google Cloud DNS API only accepts a single resource record for each name and type combination (with multiple data elements), the zone file’s records are merged as necessary. During this merge, the lowest ttl of the merged records is used. If none of the merged records have a ttl value, the zone file’s global TTL is used for the record.
The following record types are supported: A, AAAA, CNAME, MX, NAPTR, NS, PTR, SOA, SPF, SRV, and TXT.
Instance Method Summary collapse
-
#initialize(zone, path_or_io) ⇒ Importer
constructor
Creates a new Importer that immediately parses the provided zone file data and creates Record instances.
-
#records(only: nil, except: nil) ⇒ Object
Returns the Record instances created from the zone file.
Constructor Details
#initialize(zone, path_or_io) ⇒ Importer
Creates a new Importer that immediately parses the provided zone file data and creates Record instances.
Parameters
path_or_io-
The path to a zone file on the filesystem, or an IO instance from which zone file data can be read. (
StringorIO)
49 50 51 52 53 54 55 56 57 |
# File 'lib/gcloud/dns/importer.rb', line 49 def initialize zone, path_or_io @zone = zone @merged_zf_records = {} @records = [] @zonefile = create_zonefile path_or_io merge_zonefile_records from_zonefile_records @records.unshift soa_record end |
Instance Method Details
#records(only: nil, except: nil) ⇒ Object
Returns the Record instances created from the zone file.
Parameters
only-
Include only records of this type or types. (
StringorArray) except-
Exclude records of this type or types. (
StringorArray)
Returns
An array of unsaved Record instances.
73 74 75 76 77 78 |
# File 'lib/gcloud/dns/importer.rb', line 73 def records only: nil, except: nil ret = @records ret = ret.select { |r| Array(only).include? r.type } if only ret = ret.reject { |r| Array(except).include? r.type } if except ret end |