Module: Zonify::YAML
Instance Method Summary collapse
- #format(records, suffix = '') ⇒ Object
- #read(text) ⇒ Object
- #sorted_hash(h) ⇒ Object
- #trim_lines(yaml) ⇒ Object
Instance Method Details
#format(records, suffix = '') ⇒ Object
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 |
# File 'lib/zonify.rb', line 488 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) ⇒ Object
510 511 512 513 514 515 |
# File 'lib/zonify.rb', line 510 def read(text) yaml = ::YAML.load(text) if yaml['suffix'] [yaml['suffix'], (yaml['records'] or {})] end end |
#sorted_hash(h) ⇒ Object
503 504 505 506 507 508 509 |
# File 'lib/zonify.rb', line 503 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) ⇒ Object
516 517 518 519 520 521 |
# File 'lib/zonify.rb', line 516 def trim_lines(yaml) lines = yaml.lines.to_a lines.shift if /^---/.match(lines[0]) lines.pop if /^$/.match(lines[-1]) lines end |