module PSON::Pure::Generator::GeneratorMethods::Array
Public Instance Methods
to_pson(state = nil, depth = 0, *)
click to toggle source
Returns a PSON
string containing a PSON
array, that is unparsed from this Array
instance. state is a PSON::State object, that can also be used to configure the produced PSON
string output further. depth is used to find out nesting depth, to indent accordingly.
# File lib/puppet/external/pson/pure/generator.rb 270 def to_pson(state = nil, depth = 0, *) 271 if state 272 state = PSON.state.from_state(state) 273 state.check_max_nesting(depth) 274 pson_check_circular(state) { pson_transform(state, depth) } 275 else 276 pson_transform(state, depth) 277 end 278 end
Private Instance Methods
pson_check_circular(state) { || ... }
click to toggle source
# File lib/puppet/external/pson/pure/generator.rb 282 def pson_check_circular(state) 283 if state and state.check_circular? 284 state.seen?(self) and raise PSON::CircularDatastructure, 285 "circular data structures not supported!" 286 state.remember self 287 end 288 yield 289 ensure 290 state and state.forget self 291 end
pson_shift(state, depth)
click to toggle source
# File lib/puppet/external/pson/pure/generator.rb 293 def pson_shift(state, depth) 294 state and not state.array_nl.empty? or return '' 295 state.indent * depth 296 end
pson_transform(state, depth)
click to toggle source
# File lib/puppet/external/pson/pure/generator.rb 298 def pson_transform(state, depth) 299 delim = ',' 300 if state 301 delim << state.array_nl 302 result = '[' 303 result << state.array_nl 304 result << map { |value| 305 pson_shift(state, depth + 1) << value.to_pson(state, depth + 1) 306 }.join(delim) 307 result << state.array_nl 308 result << pson_shift(state, depth) 309 result << ']' 310 else 311 '[' << map { |value| value.to_pson }.join(delim) << ']' 312 end 313 end