Class Methods
# File lib/puppet/util/zaml.rb, line 52 def self.dump(stuff, where='') z = new stuff.to_zaml(z) where << z.to_s end
Instance Methods
# File lib/puppet/util/zaml.rb, line 61 def initialize @result = [] @indent = nil @structured_key_prefix = nil @previously_emitted_object = {} @next_free_label_number = 0 emit('--- ') end
# File lib/puppet/util/zaml.rb, line 143 def emit(s) @result << s @recent_nl = false unless s.kind_of?(Label) end
# File lib/puppet/util/zaml.rb, line 121 def first_time_only(obj) if label = label_for(obj) label.this_label_number ||= (@next_free_label_number += 1) emit(label.reference) else with_structured_prefix(obj) do emit(new_label_for(obj)) yield end end end
# File lib/puppet/util/zaml.rb, line 111 def label_for(obj) @previously_emitted_object[obj.object_id] end
# File lib/puppet/util/zaml.rb, line 70 def nested(tail=' ') old_indent = @indent @indent = "#{@indent || "\n"}#{tail}" yield @indent = old_indent end
# File lib/puppet/util/zaml.rb, line 115 def new_label_for(obj) label = Label.new(obj,(Hash === obj || Array === obj) ? "#{@indent || "\n"} " : ' ') @previously_emitted_object[obj.object_id] = label label end
# File lib/puppet/util/zaml.rb, line 148 def nl(s = nil) emit(@indent || "\n") unless @recent_nl emit(s) if s @recent_nl = true end
# File lib/puppet/util/zaml.rb, line 158 def prefix_structured_keys(x) @structured_key_prefix = x yield nl unless @structured_key_prefix @structured_key_prefix = nil end
# File lib/puppet/util/zaml.rb, line 154 def to_s @result.join end
# File lib/puppet/util/zaml.rb, line 133 def with_structured_prefix(obj) if @structured_key_prefix unless obj.is_a?(String) and obj !~ /\n/ emit(@structured_key_prefix) @structured_key_prefix = nil end end yield end