Class: Zerigo::DNS::Host

Inherits:
Base
  • Object
show all
Defined in:
lib/zerigo_dns.rb

Class Method Summary collapse

Methods inherited from Base

#load

Class Method Details

.find_by_hostname(zone, hostname) ⇒ Object

Find by host name



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/zerigo_dns.rb', line 83

def self.find_by_hostname(zone, hostname)
  hosts = find(:all, :params=> { :zone_id => zone }) 
  host = nil
  hosts.each do |h|
    if h.hostname == hostname
      host = h
      break;
    end
  end      
  host
end

.update_or_create(zone, hostname, type, ttl, data) ⇒ Object

Update or Create Host for a zone



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/zerigo_dns.rb', line 96

def self.update_or_create(zone, hostname, type, ttl, data)
  host = find_by_hostname(zone, hostname)
  if host
    # update
    host.host_type  = type
    host.data       = data
    host.ttl        = ttl
    host.save
  else
    # create
    host = create(
      :zone_id    => zone, 
      :hostname   => hostname,
      :host_type  => type,
      :data       => data,
      :ttl        => ttl
    )
  end  
  host
end