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/octocatalog-diff/external/pson/pure/generator.rb, line 270 def to_pson(state = nil, depth = 0, *) if state state = PSON.state.from_state(state) state.check_max_nesting(depth) pson_check_circular(state) { pson_transform(state, depth) } else pson_transform(state, depth) end end
Private Instance Methods
pson_check_circular(state) { || ... }
click to toggle source
# File lib/octocatalog-diff/external/pson/pure/generator.rb, line 282 def pson_check_circular(state) if state and state.check_circular? state.seen?(self) and raise PSON::CircularDatastructure, "circular data structures not supported!" state.remember self end yield ensure state and state.forget self end
pson_shift(state, depth)
click to toggle source
# File lib/octocatalog-diff/external/pson/pure/generator.rb, line 293 def pson_shift(state, depth) state and not state.array_nl.empty? or return '' state.indent * depth end
pson_transform(state, depth)
click to toggle source
# File lib/octocatalog-diff/external/pson/pure/generator.rb, line 298 def pson_transform(state, depth) delim = ',' if state delim << state.array_nl result = '[' result << state.array_nl result << map { |value| pson_shift(state, depth + 1) << value.to_pson(state, depth + 1) }.join(delim) result << state.array_nl result << pson_shift(state, depth) result << ']' else '[' << map { |value| value.to_pson }.join(delim) << ']' end end