class RedZone::ZonefileWriter

Writes zone configurations to files

Public Class Methods

new(zone_config) click to toggle source

Constructs a ZonefileWriter

# File lib/redzone/zonefile_writer.rb, line 8
def initialize(zone_config)
  @config = zone_config
end

Public Instance Methods

write_zones(target) click to toggle source

Write the zone database files to the target folder @param [Pathname] target Target directory

# File lib/redzone/zonefile_writer.rb, line 13
def write_zones(target)
  raise ArgumentError, "Directory #{target} does not exist" unless target.exist?
  @config.zones.each do |z|
    with_file(target,z.name) { |io| z.write(io) } 
  end
  @config.arpas.each do |a|
    with_file(target,a.name) {|io| a.write(io)}
  end
end

Private Instance Methods

with_file(target,name,&block) click to toggle source
# File lib/redzone/zonefile_writer.rb, line 23
def with_file(target,name,&block)
  filename = target + "#{name}.db"
  File.open(filename,"w") do |file|
    block.call(file)
  end
end