multi_json 1.7.3 → 1.7.4

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ 1.7.4
2
+ -----
3
+ * [Cache options for better performance](https://github.com/intridea/multi_json/commit/8a26ee93140c4bed36194ed9fb887a1b6919257b)
4
+
1
5
  1.7.3
2
6
  -----
3
7
  * [Require json/ext to ensure extension version gets loaded for json_gem](https://github.com/intridea/multi_json/commit/942686f7e8597418c6f90ee69e1d45242fac07b1)
data/lib/multi_json.rb CHANGED
@@ -27,6 +27,14 @@ module MultiJson
27
27
  self.load_options = self.dump_options = value
28
28
  end
29
29
 
30
+ # cache busting
31
+ %w(load_options= dump_options=).each do |method|
32
+ define_method method do |*args|
33
+ use current_adapter
34
+ super *args
35
+ end
36
+ end
37
+
30
38
  ALIASES = {
31
39
  'jrjackson' => :jr_jackson
32
40
  }
@@ -51,7 +59,7 @@ module MultiJson
51
59
  return :gson if defined?(::Gson)
52
60
  return :jr_jackson if defined?(::JrJackson)
53
61
 
54
- REQUIREMENT_MAP.each do |(library, adapter)|
62
+ REQUIREMENT_MAP.each do |library, adapter|
55
63
  begin
56
64
  require library
57
65
  return adapter
@@ -15,27 +15,33 @@ module MultiJson
15
15
  end
16
16
  end
17
17
 
18
+ def activate!
19
+ @load_options_cache = {}
20
+ @dump_options_cache = {}
21
+ instance.activate if instance.respond_to?(:activate)
22
+ end
23
+
18
24
  def load(string, options={})
19
- instance.load(string, collect_load_options(string, options))
25
+ instance.load(string, collect_load_options(string, options).clone)
20
26
  end
21
27
 
22
28
  def dump(object, options={})
23
- instance.dump(object, collect_dump_options(object, options))
29
+ instance.dump(object, collect_dump_options(object, options).clone)
24
30
  end
25
31
 
26
32
  protected
27
33
 
28
34
  def collect_load_options(string, options)
29
- collect_options :load_options, options, [ string, options ]
35
+ @load_options_cache[options] ||= collect_options(:load_options, options).merge(options)
30
36
  end
31
37
 
32
38
  def collect_dump_options(object, options)
33
- collect_options :dump_options, options, [ object, options ]
39
+ @dump_options_cache[options] ||= collect_options(:dump_options, options).merge(options)
34
40
  end
35
41
 
36
- def collect_options(method, overrides, args)
42
+ def collect_options(method, *args)
37
43
  global, local = *[MultiJson, self].map{ |r| r.send(method, *args) }
38
- local.merge(global).merge(overrides)
44
+ local.merge(global)
39
45
  end
40
46
 
41
47
  end
@@ -7,7 +7,7 @@ module MultiJson
7
7
 
8
8
  GEM_VERSION = '1.7.7'
9
9
 
10
- def self.activate!
10
+ def activate
11
11
  if JSON::VERSION < GEM_VERSION
12
12
  Kernel.warn "You are using an old or stdlib version of #{gem_name} gem\n" +
13
13
  "Please upgrade to the recent version by adding this to your Gemfile:\n\n" +
@@ -7,7 +7,7 @@ module MultiJson
7
7
  class JsonGem < JsonCommon
8
8
  ParseError = ::JSON::ParserError
9
9
 
10
- def self.gem_name
10
+ def gem_name
11
11
  'json'
12
12
  end
13
13
  end
@@ -7,7 +7,7 @@ module MultiJson
7
7
  class JsonPure < JsonCommon
8
8
  ParseError = ::JSON::ParserError
9
9
 
10
- def self.gem_name
10
+ def gem_name
11
11
  'json_pure'
12
12
  end
13
13
  end
@@ -1,3 +1,3 @@
1
1
  module MultiJson
2
- VERSION = '1.7.3' unless defined?(MultiJson::VERSION)
2
+ VERSION = '1.7.4' unless defined?(MultiJson::VERSION)
3
3
  end
@@ -50,6 +50,18 @@ describe 'MultiJson' do
50
50
  end
51
51
  end
52
52
 
53
+ context 'caching' do
54
+ before{ MultiJson.use :json_gem }
55
+ let(:json_string){ '{"abc":"def"}' }
56
+
57
+ it 'busts options caches on change' do
58
+ MultiJson.load_options = { :symbolize_keys => true }
59
+ expect(MultiJson.load(json_string)).to eq(:abc => 'def')
60
+ MultiJson.load_options = nil
61
+ expect(MultiJson.load(json_string)).to eq('abc' => 'def')
62
+ end
63
+ end
64
+
53
65
  context 'with stdlib version' do
54
66
  around do |example|
55
67
  version = JSON::VERSION
@@ -63,7 +75,7 @@ describe 'MultiJson' do
63
75
  MultiJson.use :json_gem
64
76
  end
65
77
 
66
- it 'should warb about json/pure' do
78
+ it 'should warn about json/pure' do
67
79
  Kernel.should_receive(:warn).with(/'json_pure', '~> 1.7.7'/)
68
80
  MultiJson.use :json_pure
69
81
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.3
4
+ version: 1.7.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -39,7 +39,7 @@ cert_chain:
39
39
  U0xxV3ZRUnNCbHlwSGZoczZKSnVMbHlaUEdoVTNSL3YKU2YzbFZLcEJDV2dS
40
40
  cEdUdnk0NVhWcEIrNTl5MzNQSm1FdVExUFRFT1l2UXlhbzlVS01BQWFBTi83
41
41
  cVdRdGpsMApobHc9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
42
- date: 2013-05-05 00:00:00.000000000 Z
42
+ date: 2013-05-26 00:00:00.000000000 Z
43
43
  dependencies:
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: bundler
metadata.gz.sig CHANGED
Binary file