class Google::Cloud::Dns::Zone::Transaction
# DNS Zone
Transaction
This object is used by {Zone#update} when passed a block. These methods are used to update the records that are sent to the Google
Cloud
DNS API.
@example
require "google/cloud/dns" dns = Google::Cloud::Dns.new zone = dns.zone "example-com" zone.update do |tx| tx.add "example.com.", "A", 86400, "1.2.3.4" tx.remove "example.com.", "TXT" tx.replace "example.com.", "MX", 86400, ["10 mail1.example.com.", "20 mail2.example.com."] tx.modify "www.example.com.", "CNAME" do |cname| cname.ttl = 86400 # only change the TTL end end
Attributes
@private
@private
Public Class Methods
@private Creates a new transaction.
# File lib/google/cloud/dns/zone/transaction.rb, line 48 def initialize zone @zone = zone @additions = [] @deletions = [] end
Public Instance Methods
Adds a record to the Zone
.
@param [String] name The owner of the record. For example:
`example.com.`.
@param [String] type The identifier of a [supported record
type](https://cloud.google.com/dns/what-is-cloud-dns). For example: `A`, `AAAA`, `CNAME`, `MX`, or `TXT`.
@param [Integer] ttl The number of seconds that the record can be
cached by resolvers.
@param [String, Array<String>] data The resource record data, as
determined by `type` and defined in [RFC 1035 (section 5)](http://tools.ietf.org/html/rfc1035#section-5) and [RFC 1034 (section 3.6.1)](http://tools.ietf.org/html/rfc1034#section-3.6.1). For example: `192.0.2.1` or `example.com.`.
@example
require "google/cloud/dns" dns = Google::Cloud::Dns.new zone = dns.zone "example-com" zone.update do |tx| tx.add "example.com.", "A", 86400, "1.2.3.4" end
# File lib/google/cloud/dns/zone/transaction.rb, line 80 def add name, type, ttl, data @additions += Array(@zone.record(name, type, ttl, data)) end
Modifies records on the Zone
. Records matching the `name` and `type` are yielded to the block where they can be modified.
@param [String] name The owner of the record. For example:
`example.com.`.
@param [String] type The identifier of a [supported record
type](https://cloud.google.com/dns/what-is-cloud-dns). For example: `A`, `AAAA`, `CNAME`, `MX`, or `TXT`.
@yield [record] a block yielding each matching record @yieldparam [Record] record the record to be modified
@example
require "google/cloud/dns" dns = Google::Cloud::Dns.new zone = dns.zone "example-com" zone.update do |tx| tx.modify "www.example.com.", "CNAME" do |cname| cname.ttl = 86400 # only change the TTL end end
# File lib/google/cloud/dns/zone/transaction.rb, line 165 def modify name, type, &block existing = @zone.records(name, type).all.to_a updated = existing.map(&:dup) updated.each(&block) @additions += updated @deletions += existing end
Removes records from the Zone
. The records are looked up before they are removed.
@param [String] name The owner of the record. For example:
`example.com.`.
@param [String] type The identifier of a [supported record
type](https://cloud.google.com/dns/what-is-cloud-dns). For example: `A`, `AAAA`, `CNAME`, `MX`, or `TXT`.
@example
require "google/cloud/dns" dns = Google::Cloud::Dns.new zone = dns.zone "example-com" zone.update do |tx| tx.remove "example.com.", "TXT" end
# File lib/google/cloud/dns/zone/transaction.rb, line 103 def remove name, type @deletions += @zone.records(name, type).all.to_a end
Replaces existing records on the Zone
. Records matching the `name` and `type` are replaced.
@param [String] name The owner of the record. For example:
`example.com.`.
@param [String] type The identifier of a [supported record
type](https://cloud.google.com/dns/what-is-cloud-dns). For example: `A`, `AAAA`, `CNAME`, `MX`, or `TXT`.
@param [Integer] ttl The number of seconds that the record can be
cached by resolvers.
@param [String, Array<String>] data The resource record data, as
determined by `type` and defined in [RFC 1035 (section 5)](http://tools.ietf.org/html/rfc1035#section-5) and [RFC 1034 (section 3.6.1)](http://tools.ietf.org/html/rfc1034#section-3.6.1). For example: `192.0.2.1` or `example.com.`.
@example
require "google/cloud/dns" dns = Google::Cloud::Dns.new zone = dns.zone "example-com" zone.update do |tx| tx.replace "example.com.", "MX", 86400, ["10 mail1.example.com.", "20 mail2.example.com."] end
# File lib/google/cloud/dns/zone/transaction.rb, line 137 def replace name, type, ttl, data remove name, type add name, type, ttl, data end