Class: Gcloud::Dns::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/gcloud/dns/record.rb,
lib/gcloud/dns/record/list.rb

Overview

DNS Record

Represents a set of DNS resource records (RRs) for a given #name and #type in a Zone. Since it is a value object, a newly created Record instance is transient until it is added to a Zone with Zone#update. Note that Zone#add and the Zone#update block parameter can be used instead of Zone#record or Record.new to create new records.

Examples:

require "gcloud"

gcloud = Gcloud.new
dns = gcloud.dns
zone = dns.zone "example-com"

zone.records.count #=> 2
record = zone.record "example.com.", "A", 86400, "1.2.3.4"
zone.records.count #=> 2
change = zone.update record
zone.records.count #=> 3

Defined Under Namespace

Classes: List

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, ttl, data) ⇒ Record

Creates a Record value object.

Parameters:

  • name (String)

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

  • type (String)

    The identifier of a supported record type. 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) and RFC 1034 (section 3.6.1). For example: ["10 mail.example.com.", "20 mail2.example.com."].


94
95
96
97
98
99
100
101
102
103
# File 'lib/gcloud/dns/record.rb', line 94

def initialize name, type, ttl, data
  fail ArgumentError, "name is required" unless name
  fail ArgumentError, "type is required" unless type
  fail ArgumentError, "ttl is required" unless ttl
  fail ArgumentError, "data is required" unless data
  @name = name.to_s
  @type = type.to_s.upcase
  @ttl = Integer(ttl)
  @data = Array(data)
end

Instance Attribute Details

#dataArray<String>

The array of resource record data, as determined by type and defined in RFC 1035 (section 5) and RFC 1034 (section 3.6.1). For example: ["10 mail.example.com.", "20 mail2.example.com."].

Returns:

  • (Array<String>)

75
76
77
# File 'lib/gcloud/dns/record.rb', line 75

def data
  @data
end

#nameString

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

Returns:

  • (String)

48
49
50
# File 'lib/gcloud/dns/record.rb', line 48

def name
  @name
end

#ttlInteger

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

Returns:

  • (Integer)

64
65
66
# File 'lib/gcloud/dns/record.rb', line 64

def ttl
  @ttl
end

#typeString

The identifier of a supported record type . For example: A, AAAA, CNAME, MX, or TXT.

Returns:

  • (String)

57
58
59
# File 'lib/gcloud/dns/record.rb', line 57

def type
  @type
end

Instance Method Details

#dupObject

Returns a deep copy of the record. Useful for updating records, since the original, unmodified record must be passed for deletion when using Zone#update.


119
120
121
122
123
# File 'lib/gcloud/dns/record.rb', line 119

def dup
  other = super
  other.data = data.map(&:dup)
  other
end