Class: Gcloud::Dns::Zone::Transaction
- Inherits:
-
Object
- Object
- Gcloud::Dns::Zone::Transaction
- Defined in:
- lib/gcloud/dns/zone/transaction.rb
Overview
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.
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
-
#additions ⇒ Object
readonly
:nodoc:.
-
#deletions ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
-
#add(name, type, ttl, data) ⇒ Object
Adds a record to the Zone.
-
#initialize(zone) ⇒ Transaction
constructor
Creates a new transaction.
-
#modify(name, type) ⇒ Object
Modifies records on the Zone.
-
#remove(name, type) ⇒ Object
Removes records from the Zone.
-
#replace(name, type, ttl, data) ⇒ Object
Replaces existing records on the Zone.
Constructor Details
#initialize(zone) ⇒ Transaction
Creates a new transaction.
46 47 48 49 50 |
# File 'lib/gcloud/dns/zone/transaction.rb', line 46 def initialize zone #:nodoc: @zone = zone @additions = [] @deletions = [] end |
Instance Attribute Details
#additions ⇒ Object (readonly)
:nodoc:
42 43 44 |
# File 'lib/gcloud/dns/zone/transaction.rb', line 42 def additions @additions end |
#deletions ⇒ Object (readonly)
:nodoc:
42 43 44 |
# File 'lib/gcloud/dns/zone/transaction.rb', line 42 def deletions @deletions end |
Instance Method Details
#add(name, type, ttl, data) ⇒ Object
Adds a record to the Zone.
Parameters
name-
The owner of the record. For example:
example.com.. (String) type-
The identifier of a supported record type. For example:
A,AAAA,CNAME,MX, orTXT. (String) ttl-
The number of seconds that the record can be cached by resolvers. (
Integer) data-
The resource record data, as determined by
typeand defined in RFC 1035 (section 5) and RFC 1034 (section 3.6.1). For example:192.0.2.1orexample.com.. (StringorArrayofString)
Example
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
85 86 87 |
# File 'lib/gcloud/dns/zone/transaction.rb', line 85 def add name, type, ttl, data @additions += Array(@zone.record(name, type, ttl, data)) end |
#modify(name, type) ⇒ Object
Modifies records on the Zone. Records matching the name and type are yielded to the block where they can be modified.
Parameters
name-
The owner of the record. For example:
example.com.. (String) type-
The identifier of a supported record type. For example:
A,AAAA,CNAME,MX, orTXT. (String)
Example
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
182 183 184 185 186 187 188 |
# File 'lib/gcloud/dns/zone/transaction.rb', line 182 def modify name, type existing = @zone.records(name: name, type: 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.
Parameters
name-
The owner of the record. For example:
example.com.. (String) type-
The identifier of a supported record type. For example:
A,AAAA,CNAME,MX, orTXT. (String)
Example
require "gcloud"
gcloud = Gcloud.new
dns = gcloud.dns
zone = dns.zone "example-com"
zone.update do |tx|
tx.remove "example.com.", "TXT"
end
113 114 115 |
# File 'lib/gcloud/dns/zone/transaction.rb', line 113 def remove name, type @deletions += @zone.records(name: name, type: type).all end |
#replace(name, type, ttl, data) ⇒ Object
Replaces existing records on the Zone. Records matching the name and type are replaced.
Parameters
name-
The owner of the record. For example:
example.com.. (String) type-
The identifier of a supported record type. For example:
A,AAAA,CNAME,MX, orTXT. (String) ttl-
The number of seconds that the record can be cached by resolvers. (
Integer) data-
The resource record data, as determined by
typeand defined in RFC 1035 (section 5) and RFC 1034 (section 3.6.1). For example:192.0.2.1orexample.com.. (StringorArrayofString)
Example
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
152 153 154 155 |
# File 'lib/gcloud/dns/zone/transaction.rb', line 152 def replace name, type, ttl, data remove name, type add name, type, ttl, data end |