module PSON::Pure::Generator::GeneratorMethods::Hash
Public Instance Methods
to_pson(state = nil, depth = 0, *)
click to toggle source
Returns a PSON
string containing a PSON
object, that is unparsed from this Hash
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 208 def to_pson(state = nil, depth = 0, *) 209 if state 210 state = PSON.state.from_state(state) 211 state.check_max_nesting(depth) 212 pson_check_circular(state) { pson_transform(state, depth) } 213 else 214 pson_transform(state, depth) 215 end 216 end
Private Instance Methods
pson_check_circular(state) { || ... }
click to toggle source
# File lib/puppet/external/pson/pure/generator.rb 220 def pson_check_circular(state) 221 if state and state.check_circular? 222 state.seen?(self) and raise PSON::CircularDatastructure, 223 "circular data structures not supported!" 224 state.remember self 225 end 226 yield 227 ensure 228 state and state.forget self 229 end
pson_shift(state, depth)
click to toggle source
# File lib/puppet/external/pson/pure/generator.rb 231 def pson_shift(state, depth) 232 state and not state.object_nl.empty? or return '' 233 state.indent * depth 234 end
pson_transform(state, depth)
click to toggle source
# File lib/puppet/external/pson/pure/generator.rb 236 def pson_transform(state, depth) 237 delim = ',' 238 if state 239 delim << state.object_nl 240 result = '{' 241 result << state.object_nl 242 result << map { |key,value| 243 s = pson_shift(state, depth + 1) 244 s << key.to_s.to_pson(state, depth + 1) 245 s << state.space_before 246 s << ':' 247 s << state.space 248 s << value.to_pson(state, depth + 1) 249 }.join(delim) 250 result << state.object_nl 251 result << pson_shift(state, depth) 252 result << '}' 253 else 254 result = '{' 255 result << map { |key,value| 256 key.to_s.to_pson << ':' << value.to_pson 257 }.join(delim) 258 result << '}' 259 end 260 result 261 end