Class: ZerigoDNS::Host
- Defined in:
- lib/zerigodns/host.rb
Class Method Summary collapse
- .find_all_by_hostname(zone, hostname) ⇒ Object
-
.find_by_zone_and_hostname(which, zone, hostname) ⇒ Object
Find host record(s) by zone and hostname.
-
.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.
Instance Method Summary collapse
-
#update_record(type, ttl, data) ⇒ Boolean, #read
Convienence method to update the record.
Methods inherited from Base
Class Method Details
.find_all_by_hostname(zone, hostname) ⇒ Object
14 15 16 |
# File 'lib/zerigodns/host.rb', line 14 def find_all_by_hostname zone, hostname find_by_zone_and_hostname(:all, zone, hostname) end |
.find_by_zone_and_hostname(which, zone, hostname) ⇒ Object
Find host record(s) by zone and hostname
9 10 11 12 |
# File 'lib/zerigodns/host.rb', line 9 def find_by_zone_and_hostname which, zone, hostname fqdn = [hostname, zone.domain].select(&:present?).join('.') find(which, params: {fqdn: fqdn, zone_id: zone.id}) end |
.find_first_by_hostname(zone, hostname) ⇒ Host
Returns The record found, or nil.
19 20 21 |
# File 'lib/zerigodns/host.rb', line 19 def find_first_by_hostname zone, hostname find_by_zone_and_hostname(:all, zone, hostname).try(: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.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/zerigodns/host.rb', line 31 def update_or_create(zone, hostname, type, ttl, data) host = find_first_by_hostname(zone, hostname) if host host.update_record(type,ttl,data) else host = create( :zone_id => zone.id, :hostname => hostname, :host_type => type, :data => data, :ttl => ttl ) end host end |
Instance Method Details
#update_record(type, ttl, data) ⇒ Boolean, #read
Convienence method to update the record.
53 54 55 56 57 58 |
# File 'lib/zerigodns/host.rb', line 53 def update_record type, ttl, data self.host_type = type self.data = data self.ttl = ttl save end |