Class: Chef::JSONCompat
- Inherits:
-
Object
- Object
- Chef::JSONCompat
- Defined in:
- lib/chef/json_compat.rb
Constant Summary collapse
- JSON_MAX_NESTING =
1000
Class Method Summary collapse
-
.from_json(source, opts = {}) ⇒ Object
Just call the JSON gem’s parse method with a modified :max_nesting field.
-
.opts_add_max_nesting(opts) ⇒ Object
See PL-538.
- .to_json(obj, opts = nil) ⇒ Object
- .to_json_pretty(obj, opts = nil) ⇒ Object
Class Method Details
.from_json(source, opts = {}) ⇒ Object
Just call the JSON gem’s parse method with a modified :max_nesting field
38 39 40 |
# File 'lib/chef/json_compat.rb', line 38 def from_json(source, opts = {}) ::JSON.parse(source, opts_add_max_nesting(opts)) end |
.opts_add_max_nesting(opts) ⇒ Object
See PL-538. Increase the max nesting for JSON, which defaults to 19, and isn’t enough for some deep node (for example) structures.
29 30 31 32 33 34 35 |
# File 'lib/chef/json_compat.rb', line 29 def opts_add_max_nesting(opts) if opts.nil? || !opts.has_key?(:max_nesting) opts = opts.nil? ? Hash.new : opts.clone opts[:max_nesting] = JSON_MAX_NESTING end opts end |
.to_json(obj, opts = nil) ⇒ Object
42 43 44 45 |
# File 'lib/chef/json_compat.rb', line 42 def to_json(obj, opts = nil) #::JSON.generate(obj, opts_add_max_nesting(opts)) obj.to_json(opts_add_max_nesting(opts)) end |
.to_json_pretty(obj, opts = nil) ⇒ Object
47 48 49 |
# File 'lib/chef/json_compat.rb', line 47 def to_json_pretty(obj, opts = nil) ::JSON.pretty_generate(obj, opts_add_max_nesting(opts)) end |