Module: Jinx::JSON::State

Defined in:
lib/jinx/json/state.rb

Overview

This State module bumps the JSON default :max_nesting to 100 and tracks the visited objects in a modified JSON::Pure::Generator::State.

Class Method Summary collapse

Class Method Details

.for(opts) ⇒ Object

return [State] the state for the given options

Parameters:

  • opts (Hash, nil)

    the generator options



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/jinx/json/state.rb', line 10

def self.for(opts)
  opts ||= {}
  opts[:max_nesting] ||= 100
  state = ::JSON::Pure::Generator::State.from_state(opts)
  class << state 
    # @return [<Jinx::JSON::Serializable>] the serialized objects
    def visited
      @visited ||= Set.new
    end
  end
  state
end