Class: Fog::DNS::Dynect::Record

Inherits:
Model
  • Object
show all
Extended by:
Fog::Deprecation
Defined in:
lib/rackspace-fog/dynect/models/dns/record.rb

Instance Attribute Summary

Attributes inherited from Model

#collection, #connection

Instance Method Summary collapse

Methods included from Fog::Deprecation

deprecate, self_deprecate

Methods inherited from Model

#initialize, #inspect, #reload, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires, #requires_one

Constructor Details

This class inherits a constructor from Fog::Model

Instance Method Details

#destroyObject



17
18
19
20
21
# File 'lib/rackspace-fog/dynect/models/dns/record.rb', line 17

def destroy
  requires :identity, :name, :type, :zone
  connection.delete_record(type, zone.identity, name, identity)
  true
end

#saveObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rackspace-fog/dynect/models/dns/record.rb', line 23

def save
  requires :name, :type, :rdata, :zone

  options = {
    :ttl => ttl
  }
  options.delete_if {|key, value| value.nil?}

  data = connection.post_record(type, zone.identity, name, rdata, options).body['data']
  # avoid overwriting zone object with zone string
  data = data.reject {|key, value| key == 'zone'}
  merge_attributes(data)

  zone.publish
  records = connection.get_record(type, zone.identity, name).body['data']
  # data in format ['/REST/xRecord/domain/fqdn/identity]
  records.map! do |record|
    tokens = record.split('/')
    {
      :identity => tokens.last,
      :type     => tokens[2][0...-6] # everything before 'Record'
    }
  end
  record = records.detect {|record| record[:type] == type}
  merge_attributes(record)

  true
end

#zoneObject



52
53
54
# File 'lib/rackspace-fog/dynect/models/dns/record.rb', line 52

def zone
  @zone
end