Class: Oj::MimicDumpOption

Inherits:
Hash
  • Object
show all
Defined in:
lib/oj/mimic.rb

Overview

A bit hack-ish but does the trick. The JSON.dump_default_options is a Hash but in mimic we use a C struct to store defaults. This class creates a view onto that struct.

Instance Method Summary collapse

Constructor Details

#initializeMimicDumpOption

Returns a new instance of MimicDumpOption.



62
63
64
65
66
67
68
69
70
# File 'lib/oj/mimic.rb', line 62

def initialize()
  oo = Oj.default_options
  self.store(:max_nesting, false)
  self.store(:allow_nan, true)
  self.store(:quirks_mode, oo[:quirks_mode])
  self.store(:ascii_only, (:ascii == oo[:escape_mode]))

  super
end

Instance Method Details

#[]=(key, value) ⇒ Object



72
73
74
75
76
77
78
79
# File 'lib/oj/mimic.rb', line 72

def []=(key, value)
  case key
  when :quirks_mode
    Oj.default_options = {:quirks_mode => value}
  when :ascii_only
    Oj.default_options = {:ascii_only => value}
  end
end