# class ZAML

### Constants

VERSION

### Public Class Methods

dump(stuff, where='') click to toggle source

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

new() click to toggle source

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

### Public Instance Methods

emit(s) click to toggle source

    # File lib/puppet/util/zaml.rb, line 143
    def emit(s)
      @result << s
      @recent_nl = false unless s.kind_of?(Label)
    end

first_time_only(obj) { || ... } click to toggle source

    # 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

label_for(obj) click to toggle source

    # File lib/puppet/util/zaml.rb, line 111
    def label_for(obj)
      @previously_emitted_object[obj.object_id]
    end

nested(tail=' ') { || ... } click to toggle source

    # File lib/puppet/util/zaml.rb, line 70
    def nested(tail='  ')
      old_indent = @indent
      @indent = "#{@indent || "\n"}#{tail}"
      yield
      @indent = old_indent
    end

new_label_for(obj) click to toggle source

    # 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

nl(s = nil) click to toggle source

    # 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

prefix_structured_keys(x) { || ... } click to toggle source

    # 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

to_s() click to toggle source

    # File lib/puppet/util/zaml.rb, line 154
    def to_s
      @result.join
    end

with_structured_prefix(obj) { || ... } click to toggle source

    # 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