Class: Fog::DNS::Dynect::Records

Inherits:
Collection
  • Object
show all
Defined in:
lib/fog/dynect/models/dns/records.rb

Instance Attribute Summary

Attributes inherited from Collection

#service

Instance Method Summary collapse

Methods inherited from Collection

#clear, #create, #destroy, #initialize, #inspect, #load, model, #model, #reload, #table, #to_json

Methods included from Attributes::ClassMethods

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

Methods included from Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

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

Constructor Details

This class inherits a constructor from Fog::Collection

Instance Method Details

#all(options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fog/dynect/models/dns/records.rb', line 14

def all(options = {})
  requires :zone
  data = []
  service.get_node_list(zone.domain, options).body['data'].each do |fqdn|
    records = service.get_record('ANY', zone.domain, fqdn).body['data']

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

    data.concat(records)
  end

  # leave out the default, read only records
  data = data.reject {|record| ['NS', 'SOA'].include?(record[:type])}

  load(data)
end

#get(record_id) ⇒ Object



39
40
41
42
# File 'lib/fog/dynect/models/dns/records.rb', line 39

def get(record_id)
  # FIXME: can this be done more efficiently?
  all.detect {|record| record.identity == record_id}
end

#new(attributes = {}) ⇒ Object



44
45
46
47
# File 'lib/fog/dynect/models/dns/records.rb', line 44

def new(attributes = {})
  requires :zone
  super({ :zone => zone }.merge!(attributes))
end