multi_json 1.20.0-java → 1.21.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +118 -38
- data/lib/multi_json/adapter.rb +62 -10
- data/lib/multi_json/adapter_error.rb +1 -1
- data/lib/multi_json/adapter_selector.rb +54 -14
- data/lib/multi_json/adapters/fast_jsonparser.rb +12 -10
- data/lib/multi_json/adapters/gson.rb +21 -4
- data/lib/multi_json/adapters/jr_jackson.rb +19 -2
- data/lib/multi_json/adapters/json_gem.rb +13 -26
- data/lib/multi_json/adapters/oj.rb +6 -6
- data/lib/multi_json/adapters/oj_common.rb +1 -1
- data/lib/multi_json/adapters/yajl.rb +1 -1
- data/lib/multi_json/concurrency.rb +7 -7
- data/lib/multi_json/deprecated.rb +26 -23
- data/lib/multi_json/options.rb +97 -23
- data/lib/multi_json/options_cache/concurrent_store.rb +1 -1
- data/lib/multi_json/options_cache.rb +21 -7
- data/lib/multi_json/parse_error.rb +1 -1
- data/lib/multi_json/version.rb +6 -6
- data/lib/multi_json.rb +123 -53
- metadata +5 -7
- data/CHANGELOG.md +0 -309
- data/CONTRIBUTING.md +0 -53
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
require_relative "../adapter"
|
|
4
4
|
require "json"
|
|
5
5
|
|
|
6
|
-
module
|
|
6
|
+
module MultiJSON
|
|
7
7
|
module Adapters
|
|
8
8
|
# Use the JSON gem to dump/load.
|
|
9
9
|
class JsonGem < Adapter
|
|
@@ -22,25 +22,29 @@ module MultiJson
|
|
|
22
22
|
|
|
23
23
|
# Parse a JSON string into a Ruby object
|
|
24
24
|
#
|
|
25
|
+
# Non-UTF-8 strings are re-labeled via ``force_encoding`` (not
|
|
26
|
+
# transcoded) and then validated. This handles the dominant
|
|
27
|
+
# real-world case: Ruby HTTP libraries return response bodies
|
|
28
|
+
# tagged as ``ASCII-8BIT`` even when the bytes are valid UTF-8.
|
|
29
|
+
# ``encode(Encoding::UTF_8)`` would raise on any multi-byte
|
|
30
|
+
# sequence in that scenario because it tries to transcode each
|
|
31
|
+
# byte individually from ASCII-8BIT to UTF-8.
|
|
32
|
+
#
|
|
25
33
|
# @api private
|
|
26
34
|
# @param string [String] JSON string to parse
|
|
27
35
|
# @param options [Hash] parsing options
|
|
28
36
|
# @return [Object] parsed Ruby object
|
|
29
|
-
# @raise [::JSON::ParserError] when input
|
|
30
|
-
# cannot be transcoded to UTF-8
|
|
37
|
+
# @raise [::JSON::ParserError] when the input is not valid UTF-8
|
|
31
38
|
#
|
|
32
39
|
# @example Parse JSON string
|
|
33
40
|
# adapter.load('{"key":"value"}') #=> {"key" => "value"}
|
|
34
41
|
def load(string, options = {})
|
|
35
42
|
if string.encoding != Encoding::UTF_8
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
rescue Encoding::UndefinedConversionError, Encoding::InvalidByteSequenceError => e
|
|
39
|
-
raise ::JSON::ParserError, e.message
|
|
40
|
-
end
|
|
43
|
+
string = string.dup.force_encoding(Encoding::UTF_8)
|
|
44
|
+
raise ::JSON::ParserError, "Invalid UTF-8 byte sequence in JSON input" unless string.valid_encoding?
|
|
41
45
|
end
|
|
42
46
|
|
|
43
|
-
::JSON.parse(string,
|
|
47
|
+
::JSON.parse(string, options)
|
|
44
48
|
end
|
|
45
49
|
|
|
46
50
|
# Serialize a Ruby object to JSON
|
|
@@ -63,23 +67,6 @@ module MultiJson
|
|
|
63
67
|
|
|
64
68
|
::JSON.pretty_generate(json_object, PRETTY_STATE_PROTOTYPE.merge(options.except(:pretty)))
|
|
65
69
|
end
|
|
66
|
-
|
|
67
|
-
private
|
|
68
|
-
|
|
69
|
-
# Translate ``:symbolize_keys`` into JSON gem's ``:symbolize_names``
|
|
70
|
-
#
|
|
71
|
-
# Returns a new hash without mutating the input. ``options`` is the
|
|
72
|
-
# cached hash returned from {Adapter.merged_load_options}, so in-place
|
|
73
|
-
# edits would pollute the cache and corrupt subsequent calls.
|
|
74
|
-
#
|
|
75
|
-
# @api private
|
|
76
|
-
# @param options [Hash] merged load options
|
|
77
|
-
# @return [Hash] options with ``:symbolize_keys`` translated
|
|
78
|
-
def translate_load_options(options)
|
|
79
|
-
return options unless options[:symbolize_keys]
|
|
80
|
-
|
|
81
|
-
options.except(:symbolize_keys).merge(symbolize_names: true)
|
|
82
|
-
end
|
|
83
70
|
end
|
|
84
71
|
end
|
|
85
72
|
end
|
|
@@ -4,7 +4,7 @@ require "oj"
|
|
|
4
4
|
require_relative "../adapter"
|
|
5
5
|
require_relative "oj_common"
|
|
6
6
|
|
|
7
|
-
module
|
|
7
|
+
module MultiJSON
|
|
8
8
|
# Namespace for JSON adapter implementations
|
|
9
9
|
#
|
|
10
10
|
# Each adapter wraps a specific JSON library and provides a consistent
|
|
@@ -14,7 +14,7 @@ module MultiJson
|
|
|
14
14
|
class Oj < Adapter
|
|
15
15
|
include OjCommon
|
|
16
16
|
|
|
17
|
-
defaults :load, mode: :strict,
|
|
17
|
+
defaults :load, mode: :strict, symbolize_names: false
|
|
18
18
|
defaults :dump, mode: :compat, time_format: :ruby, use_to_json: true
|
|
19
19
|
|
|
20
20
|
# In certain cases the Oj gem may throw a ``JSON::ParserError``
|
|
@@ -69,10 +69,10 @@ module MultiJson
|
|
|
69
69
|
|
|
70
70
|
private
|
|
71
71
|
|
|
72
|
-
# Translate ``:
|
|
72
|
+
# Translate ``:symbolize_names`` into Oj's ``:symbol_keys``
|
|
73
73
|
#
|
|
74
74
|
# Returns a new hash without mutating the input.
|
|
75
|
-
# ``:symbol_keys`` is always set (true or false) so
|
|
75
|
+
# ``:symbol_keys`` is always set (true or false) so MultiJSON's
|
|
76
76
|
# behavior is independent of any global ``Oj.default_options``
|
|
77
77
|
# the host application may have set. The input is the cached hash
|
|
78
78
|
# returned from {Adapter.merged_load_options}, so in-place edits
|
|
@@ -80,9 +80,9 @@ module MultiJson
|
|
|
80
80
|
#
|
|
81
81
|
# @api private
|
|
82
82
|
# @param options [Hash] merged load options
|
|
83
|
-
# @return [Hash] options with ``:
|
|
83
|
+
# @return [Hash] options with ``:symbolize_names`` translated
|
|
84
84
|
def translate_load_options(options)
|
|
85
|
-
options.except(:
|
|
85
|
+
options.except(:symbolize_names).merge(symbol_keys: options[:symbolize_names] == true)
|
|
86
86
|
end
|
|
87
87
|
end
|
|
88
88
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module
|
|
4
|
-
# Catalog of process-wide mutexes used to serialize
|
|
3
|
+
module MultiJSON
|
|
4
|
+
# Catalog of process-wide mutexes used to serialize MultiJSON's lazy
|
|
5
5
|
# initializers and adapter swaps. Each mutex protects a distinct
|
|
6
6
|
# piece of mutable state. Callers go through {.synchronize} rather
|
|
7
7
|
# than touching the mutex constants directly so the constants
|
|
@@ -15,10 +15,10 @@ module MultiJson
|
|
|
15
15
|
# instance. The names are documented inline so callers can find
|
|
16
16
|
# what each mutex protects without leaving this file.
|
|
17
17
|
MUTEXES = {
|
|
18
|
-
# Guards the {DEPRECATION_WARNINGS_SHOWN} set in `
|
|
18
|
+
# Guards the {DEPRECATION_WARNINGS_SHOWN} set in `MultiJSON` so the
|
|
19
19
|
# check-then-add pair in `warn_deprecation_once` doesn't race.
|
|
20
20
|
deprecation_warnings: Mutex.new,
|
|
21
|
-
# Guards the process-wide `@adapter` swap in `
|
|
21
|
+
# Guards the process-wide `@adapter` swap in `MultiJSON.use` so two
|
|
22
22
|
# threads can't interleave their `OptionsCache.reset` and adapter
|
|
23
23
|
# assignment.
|
|
24
24
|
adapter: Mutex.new,
|
|
@@ -28,10 +28,10 @@ module MultiJson
|
|
|
28
28
|
# warning fires at most once.
|
|
29
29
|
default_adapter: Mutex.new,
|
|
30
30
|
# Guards the lazy `default_load_options` / `default_dump_options`
|
|
31
|
-
# initializers in `
|
|
31
|
+
# initializers in `MultiJSON::Options`.
|
|
32
32
|
default_options: Mutex.new,
|
|
33
33
|
# Guards the lazy dump-delegate resolution in
|
|
34
|
-
# `
|
|
34
|
+
# `MultiJSON::Adapters::FastJsonparser`.
|
|
35
35
|
dump_delegate: Mutex.new
|
|
36
36
|
}.freeze
|
|
37
37
|
private_constant :MUTEXES
|
|
@@ -49,7 +49,7 @@ module MultiJson
|
|
|
49
49
|
# @return [Object] the block's return value
|
|
50
50
|
# @raise [KeyError] when ``name`` does not match a known mutex
|
|
51
51
|
# @example
|
|
52
|
-
#
|
|
52
|
+
# MultiJSON::Concurrency.synchronize(:adapter) { ... }
|
|
53
53
|
def self.synchronize(name, &)
|
|
54
54
|
MUTEXES.fetch(name).synchronize(&)
|
|
55
55
|
end
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
#
|
|
5
5
|
# Each method here emits a one-time deprecation warning on first call and
|
|
6
6
|
# delegates to its current-API counterpart. The whole file is loaded by
|
|
7
|
-
# {
|
|
7
|
+
# {MultiJSON} so the deprecation surface stays out of the main module
|
|
8
8
|
# definition.
|
|
9
9
|
#
|
|
10
10
|
# @api private
|
|
11
|
-
module
|
|
11
|
+
module MultiJSON
|
|
12
12
|
class << self
|
|
13
13
|
private
|
|
14
14
|
|
|
@@ -17,17 +17,18 @@ module MultiJson
|
|
|
17
17
|
# The generated singleton method emits a one-time deprecation
|
|
18
18
|
# warning naming the replacement, then forwards all positional and
|
|
19
19
|
# keyword arguments plus any block to ``replacement``. Used for the
|
|
20
|
-
# ``
|
|
21
|
-
# ``default_engine`` aliases that are scheduled
|
|
20
|
+
# ``load`` / ``dump`` / ``decode`` / ``encode`` / ``engine*`` /
|
|
21
|
+
# ``with_engine`` / ``default_engine`` aliases that are scheduled
|
|
22
|
+
# for removal in v2.0.
|
|
22
23
|
#
|
|
23
24
|
# @api private
|
|
24
25
|
# @param name [Symbol] deprecated method name
|
|
25
26
|
# @param replacement [Symbol] current-API method to delegate to
|
|
26
27
|
# @return [Symbol] the defined method name
|
|
27
28
|
# @example
|
|
28
|
-
# deprecate_alias :
|
|
29
|
+
# deprecate_alias :load, :parse
|
|
29
30
|
def deprecate_alias(name, replacement)
|
|
30
|
-
message = "
|
|
31
|
+
message = "MultiJSON.#{name} is deprecated and will be removed in v2.0. Use MultiJSON.#{replacement} instead."
|
|
31
32
|
define_singleton_method(name) do |*args, **kwargs, &block|
|
|
32
33
|
warn_deprecation_once(name, message)
|
|
33
34
|
public_send(replacement, *args, **kwargs, &block)
|
|
@@ -40,8 +41,8 @@ module MultiJson
|
|
|
40
41
|
# whose body fans out to multiple replacement methods, and for the
|
|
41
42
|
# ``cached_options`` / ``reset_cached_options!`` no-op stubs that
|
|
42
43
|
# have no current-API counterpart at all. The block runs in its
|
|
43
|
-
# own lexical ``self``, which is the ``
|
|
44
|
-
# every call site sits inside ``module
|
|
44
|
+
# own lexical ``self``, which is the ``MultiJSON`` module since
|
|
45
|
+
# every call site sits inside ``module MultiJSON`` below.
|
|
45
46
|
#
|
|
46
47
|
# @api private
|
|
47
48
|
# @param name [Symbol] deprecated method name
|
|
@@ -58,8 +59,10 @@ module MultiJson
|
|
|
58
59
|
end
|
|
59
60
|
end
|
|
60
61
|
|
|
61
|
-
deprecate_alias :
|
|
62
|
-
deprecate_alias :
|
|
62
|
+
deprecate_alias :load, :parse
|
|
63
|
+
deprecate_alias :dump, :generate
|
|
64
|
+
deprecate_alias :decode, :parse
|
|
65
|
+
deprecate_alias :encode, :generate
|
|
63
66
|
deprecate_alias :engine, :adapter
|
|
64
67
|
deprecate_alias :engine=, :adapter=
|
|
65
68
|
deprecate_alias :default_engine, :default_adapter
|
|
@@ -67,18 +70,18 @@ module MultiJson
|
|
|
67
70
|
|
|
68
71
|
deprecate_method(
|
|
69
72
|
:default_options=,
|
|
70
|
-
"
|
|
71
|
-
"Use
|
|
72
|
-
) { |value| self.
|
|
73
|
+
"MultiJSON.default_options setter is deprecated\n" \
|
|
74
|
+
"Use MultiJSON.parse_options and MultiJSON.generate_options instead"
|
|
75
|
+
) { |value| self.parse_options = self.generate_options = value }
|
|
73
76
|
|
|
74
77
|
deprecate_method(
|
|
75
78
|
:default_options,
|
|
76
|
-
"
|
|
77
|
-
"Use
|
|
78
|
-
) {
|
|
79
|
+
"MultiJSON.default_options is deprecated\n" \
|
|
80
|
+
"Use MultiJSON.parse_options or MultiJSON.generate_options instead"
|
|
81
|
+
) { parse_options }
|
|
79
82
|
|
|
80
83
|
%i[cached_options reset_cached_options!].each do |name|
|
|
81
|
-
deprecate_method(name, "
|
|
84
|
+
deprecate_method(name, "MultiJSON.#{name} method is deprecated and no longer used.") { nil }
|
|
82
85
|
end
|
|
83
86
|
|
|
84
87
|
private
|
|
@@ -86,25 +89,25 @@ module MultiJson
|
|
|
86
89
|
# Instance-method delegate for the deprecated default_options setter
|
|
87
90
|
#
|
|
88
91
|
# @api private
|
|
89
|
-
# @deprecated Use {
|
|
92
|
+
# @deprecated Use {MultiJSON.load_options=} and {MultiJSON.dump_options=} instead
|
|
90
93
|
# @param value [Hash] options hash
|
|
91
94
|
# @return [Hash] the options hash
|
|
92
95
|
# @example
|
|
93
|
-
# class Foo; include
|
|
96
|
+
# class Foo; include MultiJSON; end
|
|
94
97
|
# Foo.new.send(:default_options=, symbolize_keys: true)
|
|
95
98
|
def default_options=(value)
|
|
96
|
-
|
|
99
|
+
MultiJSON.default_options = value
|
|
97
100
|
end
|
|
98
101
|
|
|
99
102
|
# Instance-method delegate for the deprecated default_options getter
|
|
100
103
|
#
|
|
101
104
|
# @api private
|
|
102
|
-
# @deprecated Use {
|
|
105
|
+
# @deprecated Use {MultiJSON.load_options} or {MultiJSON.dump_options} instead
|
|
103
106
|
# @return [Hash] the current load options
|
|
104
107
|
# @example
|
|
105
|
-
# class Foo; include
|
|
108
|
+
# class Foo; include MultiJSON; end
|
|
106
109
|
# Foo.new.send(:default_options)
|
|
107
110
|
def default_options
|
|
108
|
-
|
|
111
|
+
MultiJSON.default_options
|
|
109
112
|
end
|
|
110
113
|
end
|
data/lib/multi_json/options.rb
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module
|
|
4
|
-
# Mixin providing configurable
|
|
3
|
+
module MultiJSON
|
|
4
|
+
# Mixin providing configurable parse/generate options
|
|
5
5
|
#
|
|
6
6
|
# Supports static hashes or dynamic callables (procs/lambdas).
|
|
7
|
-
# Extended by both
|
|
7
|
+
# Extended by both MultiJSON (global options) and Adapter classes.
|
|
8
8
|
#
|
|
9
9
|
# @api private
|
|
10
10
|
module Options
|
|
@@ -15,71 +15,145 @@ module MultiJson
|
|
|
15
15
|
# because the `#:` cast only applies to method-call results.
|
|
16
16
|
EMPTY_OPTIONS = Hash.new.freeze #: options # rubocop:disable Style/EmptyLiteral
|
|
17
17
|
|
|
18
|
-
# Set options for
|
|
18
|
+
# Set options for parse operations
|
|
19
19
|
#
|
|
20
20
|
# @api public
|
|
21
21
|
# @param options [Hash, Proc] options hash or callable
|
|
22
22
|
# @return [Hash, Proc] the options
|
|
23
23
|
# @example
|
|
24
|
-
#
|
|
25
|
-
def
|
|
24
|
+
# MultiJSON.parse_options = {symbolize_keys: true}
|
|
25
|
+
def parse_options=(options)
|
|
26
26
|
OptionsCache.reset
|
|
27
|
-
@
|
|
27
|
+
@parse_options = options
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
# Set options for
|
|
30
|
+
# Set options for generate operations
|
|
31
31
|
#
|
|
32
32
|
# @api public
|
|
33
33
|
# @param options [Hash, Proc] options hash or callable
|
|
34
34
|
# @return [Hash, Proc] the options
|
|
35
35
|
# @example
|
|
36
|
-
#
|
|
37
|
-
def
|
|
36
|
+
# MultiJSON.generate_options = {pretty: true}
|
|
37
|
+
def generate_options=(options)
|
|
38
38
|
OptionsCache.reset
|
|
39
|
-
@
|
|
39
|
+
@generate_options = options
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
# Get options for
|
|
42
|
+
# Get options for parse operations
|
|
43
43
|
#
|
|
44
|
-
# When `@
|
|
44
|
+
# When `@parse_options` is a callable (proc/lambda), it's invoked
|
|
45
45
|
# with `args` as positional arguments — typically the merged
|
|
46
|
-
# options hash from `Adapter.
|
|
46
|
+
# options hash from `Adapter.merged_parse_options`. When it's a
|
|
47
47
|
# plain hash, `args` is ignored.
|
|
48
48
|
#
|
|
49
49
|
# @api public
|
|
50
50
|
# @param args [Array<Object>] forwarded to the callable, ignored otherwise
|
|
51
51
|
# @return [Hash] resolved options hash
|
|
52
52
|
# @example
|
|
53
|
-
#
|
|
53
|
+
# MultiJSON.parse_options #=> {}
|
|
54
|
+
def parse_options(*args)
|
|
55
|
+
resolve_options(@parse_options, *args) || default_parse_options
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Get options for generate operations
|
|
59
|
+
#
|
|
60
|
+
# @api public
|
|
61
|
+
# @param args [Array<Object>] forwarded to the callable, ignored otherwise
|
|
62
|
+
# @return [Hash] resolved options hash
|
|
63
|
+
# @example
|
|
64
|
+
# MultiJSON.generate_options #=> {}
|
|
65
|
+
def generate_options(*args)
|
|
66
|
+
resolve_options(@generate_options, *args) || default_generate_options
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Get default parse options
|
|
70
|
+
#
|
|
71
|
+
# @api private
|
|
72
|
+
# @return [Hash] frozen empty hash
|
|
73
|
+
def default_parse_options
|
|
74
|
+
Concurrency.synchronize(:default_options) { @default_parse_options ||= EMPTY_OPTIONS }
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Get default generate options
|
|
78
|
+
#
|
|
79
|
+
# @api private
|
|
80
|
+
# @return [Hash] frozen empty hash
|
|
81
|
+
def default_generate_options
|
|
82
|
+
Concurrency.synchronize(:default_options) { @default_generate_options ||= EMPTY_OPTIONS }
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Set options for parse operations
|
|
86
|
+
#
|
|
87
|
+
# @api public
|
|
88
|
+
# @deprecated Use {#parse_options=} instead. Will be removed in v2.0.
|
|
89
|
+
# @param options [Hash, Proc] options hash or callable
|
|
90
|
+
# @return [Hash, Proc] the options
|
|
91
|
+
# @example
|
|
92
|
+
# MultiJSON.load_options = {symbolize_keys: true}
|
|
93
|
+
def load_options=(options)
|
|
94
|
+
MultiJSON.warn_deprecation_once(:load_options=,
|
|
95
|
+
"MultiJSON.load_options= is deprecated and will be removed in v2.0. Use MultiJSON.parse_options= instead.")
|
|
96
|
+
self.parse_options = options
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Set options for generate operations
|
|
100
|
+
#
|
|
101
|
+
# @api public
|
|
102
|
+
# @deprecated Use {#generate_options=} instead. Will be removed in v2.0.
|
|
103
|
+
# @param options [Hash, Proc] options hash or callable
|
|
104
|
+
# @return [Hash, Proc] the options
|
|
105
|
+
# @example
|
|
106
|
+
# MultiJSON.dump_options = {pretty: true}
|
|
107
|
+
def dump_options=(options)
|
|
108
|
+
MultiJSON.warn_deprecation_once(:dump_options=,
|
|
109
|
+
"MultiJSON.dump_options= is deprecated and will be removed in v2.0. Use MultiJSON.generate_options= instead.")
|
|
110
|
+
self.generate_options = options
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# Get options for parse operations
|
|
114
|
+
#
|
|
115
|
+
# @api public
|
|
116
|
+
# @deprecated Use {#parse_options} instead. Will be removed in v2.0.
|
|
117
|
+
# @param args [Array<Object>] forwarded to the callable, ignored otherwise
|
|
118
|
+
# @return [Hash] resolved options hash
|
|
119
|
+
# @example
|
|
120
|
+
# MultiJSON.load_options #=> {}
|
|
54
121
|
def load_options(*args)
|
|
55
|
-
|
|
122
|
+
MultiJSON.warn_deprecation_once(:load_options,
|
|
123
|
+
"MultiJSON.load_options is deprecated and will be removed in v2.0. Use MultiJSON.parse_options instead.")
|
|
124
|
+
parse_options(*args)
|
|
56
125
|
end
|
|
57
126
|
|
|
58
|
-
# Get options for
|
|
127
|
+
# Get options for generate operations
|
|
59
128
|
#
|
|
60
129
|
# @api public
|
|
130
|
+
# @deprecated Use {#generate_options} instead. Will be removed in v2.0.
|
|
61
131
|
# @param args [Array<Object>] forwarded to the callable, ignored otherwise
|
|
62
132
|
# @return [Hash] resolved options hash
|
|
63
133
|
# @example
|
|
64
|
-
#
|
|
134
|
+
# MultiJSON.dump_options #=> {}
|
|
65
135
|
def dump_options(*args)
|
|
66
|
-
|
|
136
|
+
MultiJSON.warn_deprecation_once(:dump_options,
|
|
137
|
+
"MultiJSON.dump_options is deprecated and will be removed in v2.0. Use MultiJSON.generate_options instead.")
|
|
138
|
+
generate_options(*args)
|
|
67
139
|
end
|
|
68
140
|
|
|
69
|
-
# Get default
|
|
141
|
+
# Get default parse options
|
|
70
142
|
#
|
|
71
143
|
# @api private
|
|
144
|
+
# @deprecated Use {#default_parse_options} instead. Will be removed in v2.0.
|
|
72
145
|
# @return [Hash] frozen empty hash
|
|
73
146
|
def default_load_options
|
|
74
|
-
|
|
147
|
+
default_parse_options
|
|
75
148
|
end
|
|
76
149
|
|
|
77
|
-
# Get default
|
|
150
|
+
# Get default generate options
|
|
78
151
|
#
|
|
79
152
|
# @api private
|
|
153
|
+
# @deprecated Use {#default_generate_options} instead. Will be removed in v2.0.
|
|
80
154
|
# @return [Hash] frozen empty hash
|
|
81
155
|
def default_dump_options
|
|
82
|
-
|
|
156
|
+
default_generate_options
|
|
83
157
|
end
|
|
84
158
|
|
|
85
159
|
private
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module
|
|
3
|
+
module MultiJSON
|
|
4
4
|
# Thread-safe bounded cache for merged options hashes
|
|
5
5
|
#
|
|
6
6
|
# Caches are separated for load and dump operations. Each cache is
|
|
@@ -39,9 +39,23 @@ module MultiJson
|
|
|
39
39
|
# @api public
|
|
40
40
|
# @return [Integer] current cache size limit
|
|
41
41
|
# @example
|
|
42
|
-
#
|
|
43
|
-
#
|
|
44
|
-
|
|
42
|
+
# MultiJSON::OptionsCache.max_cache_size = 5000
|
|
43
|
+
# MultiJSON::OptionsCache.max_cache_size #=> 5000
|
|
44
|
+
attr_reader :max_cache_size
|
|
45
|
+
|
|
46
|
+
# Set the maximum number of entries per cache store
|
|
47
|
+
#
|
|
48
|
+
# @api public
|
|
49
|
+
# @param value [Integer] positive entry cap
|
|
50
|
+
# @return [Integer] the validated value
|
|
51
|
+
# @raise [ArgumentError] when value is not a positive Integer
|
|
52
|
+
# @example
|
|
53
|
+
# MultiJSON::OptionsCache.max_cache_size = 5000
|
|
54
|
+
def max_cache_size=(value)
|
|
55
|
+
raise ArgumentError, "max_cache_size must be a positive Integer, got #{value.inspect}" unless Integer === value && value.positive? # rubocop:disable Style/CaseEquality
|
|
56
|
+
|
|
57
|
+
@max_cache_size = value
|
|
58
|
+
end
|
|
45
59
|
|
|
46
60
|
# Reset both caches
|
|
47
61
|
#
|
|
@@ -57,7 +71,7 @@ module MultiJson
|
|
|
57
71
|
end
|
|
58
72
|
end
|
|
59
73
|
|
|
60
|
-
module
|
|
74
|
+
module MultiJSON
|
|
61
75
|
module OptionsCache
|
|
62
76
|
# Dynamic require path so MRI (mutex_store) and JRuby
|
|
63
77
|
# (concurrent_store) execute the same physical line, avoiding a
|
|
@@ -68,5 +82,5 @@ module MultiJson
|
|
|
68
82
|
end
|
|
69
83
|
end
|
|
70
84
|
|
|
71
|
-
require_relative "options_cache/#{
|
|
72
|
-
|
|
85
|
+
require_relative "options_cache/#{MultiJSON::OptionsCache.send(:const_get, :BACKENDS).fetch(RUBY_ENGINE, "mutex_store")}"
|
|
86
|
+
MultiJSON::OptionsCache.reset
|
data/lib/multi_json/version.rb
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module
|
|
4
|
-
# Version information for
|
|
3
|
+
module MultiJSON
|
|
4
|
+
# Version information for MultiJSON
|
|
5
5
|
#
|
|
6
6
|
# @api private
|
|
7
7
|
class Version
|
|
8
8
|
# Major version number
|
|
9
|
-
MAJOR = 1 unless defined?
|
|
9
|
+
MAJOR = 1 unless defined? MultiJSON::Version::MAJOR
|
|
10
10
|
# Minor version number
|
|
11
|
-
MINOR =
|
|
11
|
+
MINOR = 21 unless defined? MultiJSON::Version::MINOR
|
|
12
12
|
# Patch version number
|
|
13
|
-
PATCH = 0 unless defined?
|
|
13
|
+
PATCH = 0 unless defined? MultiJSON::Version::PATCH
|
|
14
14
|
# Pre-release version suffix
|
|
15
|
-
PRE = nil unless defined?
|
|
15
|
+
PRE = nil unless defined? MultiJSON::Version::PRE
|
|
16
16
|
|
|
17
17
|
class << self
|
|
18
18
|
# Return the version string
|