Class: ZerigoDNS::Host
- Includes:
- Resource
- Defined in:
- lib/zerigodns/host.rb
Constant Summary
Constants inherited from Client
Client::ACTIONS, Client::ResponseError
Instance Attribute Summary
Attributes inherited from Client
Class Method Summary collapse
-
.find_all_by_hostname(zone, hostname) ⇒ Object
Find host record(s) by zone and hostname.
-
.find_by_zone_and_hostname(which, zone, hostname) ⇒ Object
Host records, or an empty list if no records found.
-
.find_first_by_hostname(zone, hostname) ⇒ Host
The record found, or nil.
-
.update_or_create(zone, hostname, type, ttl, data) ⇒ Host
Update or Create Host for a zone This method will only update the first record.
Methods included from Resource
Methods inherited from Client
Class Method Details
.find_all_by_hostname(zone, hostname) ⇒ Object
Find host record(s) by zone and hostname
29 30 31 32 |
# File 'lib/zerigodns/host.rb', line 29 def find_all_by_hostname zone, hostname fqdn = [hostname, zone.domain].reject(&:nil?).reject(&:empty?).join('.') all(fqdn: fqdn, zone_id: zone.id) end |
.find_by_zone_and_hostname(which, zone, hostname) ⇒ Object
Returns Host records, or an empty list if no records found.
14 15 16 17 18 19 20 |
# File 'lib/zerigodns/host.rb', line 14 def find_by_zone_and_hostname which, zone, hostname if which == :all find_all_by_hostname(zone, hostname) else find_all_by_hostname(zone, hostname).send(which) end end |
.find_first_by_hostname(zone, hostname) ⇒ Host
Returns The record found, or nil.
35 36 37 |
# File 'lib/zerigodns/host.rb', line 35 def find_first_by_hostname zone, hostname find_all_by_hostname(zone, hostname).first end |
.update_or_create(zone, hostname, type, ttl, data) ⇒ Host
Update or Create Host for a zone This method will only update the first record.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/zerigodns/host.rb', line 47 def update_or_create(zone, hostname, type, ttl, data) host = find_first_by_hostname(zone, hostname) if host host.update(ttl: ttl, host_type: type, data: data) else host = create( :zone_id => zone.id, :hostname => hostname, :host_type => type, :data => data, :ttl => ttl ) end host end |