Class: Gcloud::Dns::Zone::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/gcloud/dns/zone/transaction.rb

Overview

# DNS Zone Transaction

This object is used by #update when passed a block. These methods are used to update the records that are sent to the Google Cloud DNS API.

Examples:

require "gcloud"

gcloud = Gcloud.new
dns = gcloud.dns
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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zone) ⇒ Transaction

Returns a new instance of Transaction.



48
49
50
51
52
# File 'lib/gcloud/dns/zone/transaction.rb', line 48

def initialize zone
  @zone = zone
  @additions = []
  @deletions = []
end

Instance Attribute Details

#additionsObject (readonly)



44
45
46
# File 'lib/gcloud/dns/zone/transaction.rb', line 44

def additions
  @additions
end

#deletionsObject (readonly)



44
45
46
# File 'lib/gcloud/dns/zone/transaction.rb', line 44

def deletions
  @deletions
end

Instance Method Details

#add(name, type, ttl, data) ⇒ Object

Adds a record to the Zone.

Examples:

require "gcloud"

gcloud = Gcloud.new
dns = gcloud.dns
zone = dns.zone "example-com"
zone.update do |tx|
  tx.add     "example.com.", "A",  86400, "1.2.3.4"
end

Parameters:

  • name (String)

    The owner of the record. For example: ‘example.com.`.

  • type (String)

    The identifier of a [supported record type](cloud.google.com/dns/what-is-cloud-dns). For example: ‘A`, `AAAA`, `CNAME`, `MX`, or `TXT`.

  • ttl (Integer)

    The number of seconds that the record can be cached by resolvers.

  • data (String, Array<String>)

    The resource record data, as determined by ‘type` and defined in [RFC 1035 (section 5)](tools.ietf.org/html/rfc1035#section-5) and [RFC 1034 (section 3.6.1)](tools.ietf.org/html/rfc1034#section-3.6.1). For example: `192.0.2.1` or `example.com.`.



81
82
83
# File 'lib/gcloud/dns/zone/transaction.rb', line 81

def add name, type, ttl, data
  @additions += Array(@zone.record(name, type, ttl, data))
end

#modify(name, type) {|record| ... } ⇒ Object

Modifies records on the Zone. Records matching the ‘name` and `type` are yielded to the block where they can be modified.

Examples:

require "gcloud"

gcloud = Gcloud.new
dns = gcloud.dns
zone.update do |tx|
  tx.modify "www.example.com.", "CNAME" do |cname|
    cname.ttl = 86400 # only change the TTL
  end
end

Parameters:

  • name (String)

    The owner of the record. For example: ‘example.com.`.

  • type (String)

    The identifier of a [supported record type](cloud.google.com/dns/what-is-cloud-dns). For example: ‘A`, `AAAA`, `CNAME`, `MX`, or `TXT`.

Yields:

  • (record)

    a block yielding each matching record

Yield Parameters:

  • record (Record)

    the record to be modified



166
167
168
169
170
171
172
# File 'lib/gcloud/dns/zone/transaction.rb', line 166

def modify name, type
  existing = @zone.records(name, type).all.to_a
  updated = existing.map(&:dup)
  updated.each { |r| yield r }
  @additions += updated
  @deletions += existing
end

#remove(name, type) ⇒ Object

Removes records from the Zone. The records are looked up before they are removed.

Examples:

require "gcloud"

gcloud = Gcloud.new
dns = gcloud.dns
zone = dns.zone "example-com"
zone.update do |tx|
  tx.remove  "example.com.", "TXT"
end

Parameters:

  • name (String)

    The owner of the record. For example: ‘example.com.`.

  • type (String)

    The identifier of a [supported record type](cloud.google.com/dns/what-is-cloud-dns). For example: ‘A`, `AAAA`, `CNAME`, `MX`, or `TXT`.



105
106
107
# File 'lib/gcloud/dns/zone/transaction.rb', line 105

def remove name, type
  @deletions += @zone.records(name, type).all
end

#replace(name, type, ttl, data) ⇒ Object

Replaces existing records on the Zone. Records matching the ‘name` and `type` are replaced.

Examples:

require "gcloud"

gcloud = Gcloud.new
dns = gcloud.dns
zone = dns.zone "example-com"
zone.update do |tx|
  tx.replace "example.com.", "MX", 86400, ["10 mail1.example.com.",
                                           "20 mail2.example.com."]
end

Parameters:

  • name (String)

    The owner of the record. For example: ‘example.com.`.

  • type (String)

    The identifier of a [supported record type](cloud.google.com/dns/what-is-cloud-dns). For example: ‘A`, `AAAA`, `CNAME`, `MX`, or `TXT`.

  • ttl (Integer)

    The number of seconds that the record can be cached by resolvers.

  • data (String, Array<String>)

    The resource record data, as determined by ‘type` and defined in [RFC 1035 (section 5)](tools.ietf.org/html/rfc1035#section-5) and [RFC 1034 (section 3.6.1)](tools.ietf.org/html/rfc1034#section-3.6.1). For example: `192.0.2.1` or `example.com.`.



138
139
140
141
# File 'lib/gcloud/dns/zone/transaction.rb', line 138

def replace name, type, ttl, data
  remove name, type
  add name, type, ttl, data
end