# frozen_string_literal: true module TidyJson ## # A purpose-built JSON generator. # # @api private class Serializer ## # Searches +obj+ for readable attributes, storing them as key-value pairs in # +json_hash+. # # @param obj [Object] A Ruby object that can be parsed as JSON. # @param json_hash [{String,Symbol => #to_s}] Accumulator. # @return [{String => #to_s}] A hash mapping of +obj+'s visible attributes. # @note Hashes will be searched for nested objects to a maximum depth of 2; # arrays to a maximum depth of 3. # @example # class Obj # class Child # def initialize; @a = { a: 1 } end # attr_reader :a # end # def initialize; @a = { b: Child.new } end # attr_accessor :a # end # # o = Obj.new # puts o.to_tidy_json # < 2: unreachable objects are not serialized # o.a = { b: { c: { d: Obj::Child.new } } } # puts o.to_tidy_json # <" # } # } # } # } # JSON # # # object arrays can be nested up to 3 levels deep # o.a = [ [ Obj::Child.new, [ Obj::Child.new, [ Obj::Child.new ] ] ] ] # puts o.to_tidy_json # <