Add whenever and zonefile methods

This commit is contained in:
Martin Lensment 2014-12-02 15:17:25 +02:00
parent 4e8b100f5c
commit 603cfb61ef
7 changed files with 56 additions and 1 deletions

View file

@ -1,6 +1,22 @@
class ZonefileSetting < ActiveRecord::Base
validates :origin, :ttl, :refresh, :retry, :expire, :minimum_ttl, :email, presence: true
validates :ttl, :refresh, :retry, :expire, :minimum_ttl, numericality: { only_integer: true }
def self.generate_zonefiles
pluck(:origin).each do |origin|
generate_zonefile(origin)
end
end
def self.generate_zonefile(origin)
zf = ActiveRecord::Base.connection.execute(
"select generate_zonefile('#{origin}')"
)[0]['generate_zonefile']
filename = "#{origin}.zone"
File.open("#{APP_CONFIG['zonefile_export_dir']}/#{filename}", 'w') { |f| f.write(zf) }
end
def to_s
origin
end