lib/zerigodns/host.rb in zerigodns-1.0.2 vs lib/zerigodns/host.rb in zerigodns-1.1.0

- old
+ new

@@ -1,25 +1,41 @@ -class ZerigoDNS::Host < ZerigoDNS::Base +class ZerigoDNS::Host < ZerigoDNS::Client + include ZerigoDNS::Resource + + class << self + # Find host record(s) by zone and hostname - # @param [Symbol, #read] which One of :one, :first, :last, or :all. See http://api.rubyonrails.org/v3.2.1/classes/ActiveResource/Base.html#method-c-find + # @param [Symbol, #read] which One of :one, :first, :last, or :all. # @param [Zone, #read] zone The zone from which to find the host record. + # @param [String, #read] hostname The hostname to find. # @return Host records, or an empty list if no records found. 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}) + if which == :all + find_all_by_hostname(zone, hostname) + else + find_all_by_hostname(zone, hostname).send(which) + end end + + + + # Find host record(s) by zone and hostname + # @param [Zone, #read] zone The zone from which to find the host record. + # @param [String, #read] hostname The hostname to find. + # @return Host records, or an empty list if no records found. def find_all_by_hostname zone, hostname - find_by_zone_and_hostname(:all, zone, hostname) + fqdn = [hostname, zone.domain].reject(&:nil?).reject(&:empty?).join('.') + all(fqdn: fqdn, zone_id: zone.id) end # @return [Host] The record found, or nil. def find_first_by_hostname zone, hostname - find_by_zone_and_hostname(:all, zone, hostname).try(:first) + find_all_by_hostname(zone, hostname).first end # Update or Create Host for a zone # This method will only update the _first_ record. # @param [Zone, #read] zone The zone to which the host belongs @@ -29,11 +45,11 @@ # @param [String, #read] data The data field of the record. # @return [Host] The created or updated host. def update_or_create(zone, hostname, type, ttl, data) host = find_first_by_hostname(zone, hostname) if host - host.update_record(type,ttl,data) + host.update(ttl: ttl, host_type: type, data: data) else host = create( :zone_id => zone.id, :hostname => hostname, :host_type => type, @@ -41,19 +57,7 @@ :ttl => ttl ) end host end - end - - # Convienence method to update the record. - # @param [String, #read] type - # @param [String, #read] ttl - # @param [String, #read] data - # @return [Boolean, #read] True if saved, false otherwise. - def update_record type, ttl, data - self.host_type = type - self.data = data - self.ttl = ttl - save end end