module Zonify::YAML
Public Instance Methods
format(records, suffix='')
click to toggle source
# File lib/zonify.rb, line 502 def format(records, suffix='') _suffix_ = Zonify._dot(Zonify.dot_(suffix)) entries = records.keys.sort.map do |k| if k == 'CNAME' STDERR.puts(::YAML.dump(records)) abort "A problem was found // #{ARGV[0]}" end [ k + ":\n" ] + records[k].keys.sort_by{|kk| kk.to_s }.map do |kk| sorted = Zonify::YAML.sorted_hash(records[k][kk]) lines = Zonify::YAML.trim_lines(sorted) [ kk + ":\n" ] + lines.map{|ln| ' ' + ln } end.flatten.map{|ln| ' ' + ln } end.flatten.map{|ln| ' ' + ln }.join "suffix: #{_suffix_}\nrecords:\n" + entries end
read(text)
click to toggle source
# File lib/zonify.rb, line 524 def read(text) yaml = ::YAML.load(text) if yaml['suffix'] [yaml['suffix'], (yaml['records'] or {})] end end
sorted_hash(h)
click to toggle source
# File lib/zonify.rb, line 517 def sorted_hash(h) result = ::YAML::quick_emit(h.object_id, {}) do |out| out.map do |map| h.keys.sort_by{|k| k.to_s }.each{|k| map.add(k, h[k]) } end end end
trim_lines(yaml)
click to toggle source
# File lib/zonify.rb, line 530 def trim_lines(yaml) lines = yaml.lines.to_a lines.shift if /^---/.match(lines[0]) lines.pop if /^$/.match(lines[-1]) lines end