Class: Fog::DNSimple::DNS::Record

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/dns/models/dnsimple/record.rb

Instance Attribute Summary

Attributes inherited from Model

#collection, #connection

Instance Method Summary collapse

Methods inherited from Model

#inspect, #reload, #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, #identity, #identity=, #merge_attributes, #new_record?, #requires

Constructor Details

#initialize(attributes = {}) ⇒ Record

Returns a new instance of Record.



20
21
22
23
# File 'lib/fog/dns/models/dnsimple/record.rb', line 20

def initialize(attributes={})
  self.ttl ||= 3600
  super
end

Instance Method Details

#destroyObject



25
26
27
28
# File 'lib/fog/dns/models/dnsimple/record.rb', line 25

def destroy
  connection.delete_record(zone.domain, identity)
  true
end

#saveObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fog/dns/models/dnsimple/record.rb', line 34

def save
  requires :name, :type, :ip
  options = {}
  options[:prio] = priority if priority
  options[:ttl]  = ttl if ttl

  # decide whether its a new record or update of an existing
  if id.nil?
    data = connection.create_record(zone.domain, name, type, ip, options)
  else
    options[:name] = name if name
    options[:content] = ip if ip
    options[:type] = type if type
    data = connection.update_record(zone.domain, id, options)
  end
  
  merge_attributes(data.body["record"])
  true
end

#zoneObject



30
31
32
# File 'lib/fog/dns/models/dnsimple/record.rb', line 30

def zone
  @zone
end