Class: ZAML
Defined Under Namespace
Classes: Label
Constant Summary collapse
- VERSION =
"0.1.3"
Class Method Summary collapse
-
.dump(stuff, where = '') ⇒ Object
Class Methods.
Instance Method Summary collapse
- #emit(s) ⇒ Object
- #first_time_only(obj) ⇒ Object
-
#initialize ⇒ ZAML
constructor
Instance Methods.
- #label_for(obj) ⇒ Object
- #nested(tail = ' ') ⇒ Object
- #new_label_for(obj) ⇒ Object
- #nl(s = nil) ⇒ Object
- #prefix_structured_keys(x) ⇒ Object
- #to_s ⇒ Object
- #with_structured_prefix(obj) ⇒ Object
Constructor Details
#initialize ⇒ ZAML
Instance Methods
62 63 64 65 66 67 68 69 |
# File 'lib/vendor/puppet/util/zaml.rb', line 62 def initialize @result = [] @indent = nil @structured_key_prefix = nil @previously_emitted_object = {} @next_free_label_number = 0 emit('--- ') end |
Class Method Details
.dump(stuff, where = '') ⇒ Object
Class Methods
53 54 55 56 57 |
# File 'lib/vendor/puppet/util/zaml.rb', line 53 def self.dump(stuff, where='') z = new stuff.to_zaml(z) where << z.to_s end |
Instance Method Details
#emit(s) ⇒ Object
144 145 146 147 |
# File 'lib/vendor/puppet/util/zaml.rb', line 144 def emit(s) @result << s @recent_nl = false unless s.kind_of?(Label) end |
#first_time_only(obj) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/vendor/puppet/util/zaml.rb', line 122 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) ⇒ Object
112 113 114 |
# File 'lib/vendor/puppet/util/zaml.rb', line 112 def label_for(obj) @previously_emitted_object[obj.object_id] end |
#nested(tail = ' ') ⇒ Object
71 72 73 74 75 76 |
# File 'lib/vendor/puppet/util/zaml.rb', line 71 def nested(tail=' ') old_indent = @indent @indent = "#{@indent || "\n"}#{tail}" yield @indent = old_indent end |
#new_label_for(obj) ⇒ Object
116 117 118 119 120 |
# File 'lib/vendor/puppet/util/zaml.rb', line 116 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) ⇒ Object
149 150 151 152 153 |
# File 'lib/vendor/puppet/util/zaml.rb', line 149 def nl(s = nil) emit(@indent || "\n") unless @recent_nl emit(s) if s @recent_nl = true end |
#prefix_structured_keys(x) ⇒ Object
159 160 161 162 163 164 |
# File 'lib/vendor/puppet/util/zaml.rb', line 159 def prefix_structured_keys(x) @structured_key_prefix = x yield nl unless @structured_key_prefix @structured_key_prefix = nil end |
#to_s ⇒ Object
155 156 157 |
# File 'lib/vendor/puppet/util/zaml.rb', line 155 def to_s @result.join end |