oj 3.16.4 → 3.16.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd443226b6fbe558bd4a01e5e4e2c150149e697c22c1676007f67923b9832682
4
- data.tar.gz: 0a46ac536c4fccaeac2bddde9ff8ef8d50343f5eeff3455b36c5bfb762aef073
3
+ metadata.gz: 95bab421dc901891ec12dc755e78eb02c517e34f205894c8cedeca3bc68401f6
4
+ data.tar.gz: 61707536ecd3a9a558df8872a3ce7b60fc04c47dbd6d7da703bd0605cf2e73bb
5
5
  SHA512:
6
- metadata.gz: 49e28b9151a1c84d9f97adcea6af90acd1141a194858f29e633bf5e2e1965bb5fab783c015e343f569692e6351ad3957059135f05eb50022b79ee799ae0a306a
7
- data.tar.gz: 74f69e8e14c39aee7128f8b7dc23fa1fa60a8df383dec844257e67c6e7f34c58d430ac77bc06571e8d52a29f857ee0162cba8ad1e93ac8bc1f7c2ad0260a0002
6
+ metadata.gz: a46a5aabda78c3da10739e31f403a8606de5129106dce4a8a26f84c66f3b7f63abc448944476e8780a00ba155a3f4fac00b83e92af7bfbaee9e177834351cf5d
7
+ data.tar.gz: da32618ab105131c9a30527ad5d9a1624b5f229f1e0fc06fa258732af4f3b1eb21fd45a8d8980513eede69a61ac823ddb465b5d465630dd0f8928720f7ec8e3d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 3.16.6 - 2024-09-09
4
+
5
+ - Fixed issue with Rails 7.2 that changed the order of calls to to_json and as_json.
6
+
7
+ ## 3.16.5 - 2024-08-07
8
+
9
+ - Fixed Oj::Parser so that block procedures work correctly.
10
+
3
11
  ## 3.16.4 - 2024-06-08
4
12
 
5
13
  - Fixed Oj::Parse EOF issue on larger stream input.
data/ext/oj/mimic_json.c CHANGED
@@ -905,7 +905,9 @@ oj_define_mimic_json(int argc, VALUE *argv, VALUE self) {
905
905
  }
906
906
  oj_mimic_json_methods(json);
907
907
 
908
- rb_define_method(rb_cObject, "to_json", mimic_object_to_json, -1);
908
+ if (!rb_const_defined(rb_cObject, rb_intern("ActiveSupport"))) {
909
+ rb_define_method(rb_cObject, "to_json", mimic_object_to_json, -1);
910
+ }
909
911
 
910
912
  rb_gv_set("$VERBOSE", verbose);
911
913
 
data/ext/oj/usual.c CHANGED
@@ -289,9 +289,14 @@ static void close_object(ojParser p) {
289
289
  }
290
290
  rb_hash_bulk_insert(d->vtail - head, head, obj);
291
291
  d->ktail = d->khead + c->ki;
292
+
292
293
  d->vtail = head;
293
294
  head--;
294
295
  *head = obj;
296
+ if (1 == d->vtail - d->vhead && rb_block_given_p()) {
297
+ d->vtail = d->vhead;
298
+ rb_yield(obj);
299
+ }
295
300
  }
296
301
 
297
302
  static void close_object_class(ojParser p) {
@@ -572,7 +577,18 @@ static VALUE result(ojParser p) {
572
577
  Usual d = (Usual)p->ctx;
573
578
 
574
579
  if (d->vhead < d->vtail) {
575
- return *d->vhead;
580
+ long cnt = d->vtail - d->vhead;
581
+ volatile VALUE ary;
582
+ volatile VALUE *vp;
583
+
584
+ if (1 == cnt) {
585
+ return *d->vhead;
586
+ }
587
+ ary = rb_ary_new();
588
+ for (vp = d->vhead; vp < d->vtail; vp++) {
589
+ rb_ary_push(ary, *vp);
590
+ }
591
+ return ary;
576
592
  }
577
593
  if (d->raise_on_empty) {
578
594
  rb_raise(oj_parse_error_class, "empty string");
data/lib/oj/mimic.rb CHANGED
@@ -1,11 +1,7 @@
1
1
  # frozen_string_literal: false
2
2
 
3
3
  require 'bigdecimal'
4
- begin
5
- require 'ostruct'
6
- rescue Exception
7
- # ignore
8
- end
4
+ require 'ostruct'
9
5
 
10
6
  module Oj
11
7
 
data/lib/oj/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Oj
2
2
  # Current version of the module.
3
- VERSION = '3.16.4'
3
+ VERSION = '3.16.6'
4
4
  end
@@ -19,7 +19,10 @@ require "active_support"
19
19
  Thread.abort_on_exception = true
20
20
 
21
21
  # Show backtraces for deprecated behavior for quicker cleanup.
22
- ActiveSupport::Deprecation.debug = true
22
+ if ActiveSupport::Deprecation.respond_to?(:debug)
23
+ # Rails 7.2 does not have ActiveSupport::Deprecation.debug
24
+ ActiveSupport::Deprecation.debug = true
25
+ end
23
26
 
24
27
  # Default to old to_time behavior but allow running tests with new behavior
25
28
  ActiveSupport.to_time_preserves_timezone = ENV["PRESERVE_TIMEZONES"] == "1"
data/test/foo.rb CHANGED
@@ -5,10 +5,22 @@ $LOAD_PATH << '.'
5
5
  $LOAD_PATH << File.join(__dir__, '../lib')
6
6
  $LOAD_PATH << File.join(__dir__, '../ext')
7
7
 
8
- require 'json'
9
8
  require 'oj'
10
- require 'oj/json'
11
9
 
12
- Oj.mimic_JSON
10
+ reader, writer = IO.pipe
13
11
 
14
- JSON.parse("[]")
12
+ thread =
13
+ Thread.new do
14
+ 5.times do |id|
15
+ Oj.to_stream(writer, { "id" => id })
16
+ sleep(1)
17
+ end
18
+
19
+ writer.close
20
+ end
21
+
22
+ p = Oj::Parser.new(:usual)
23
+ p.load(reader) { |data| puts "#{Time.now} -- ID: #{data["id"]}" }
24
+
25
+ reader.close
26
+ thread.join
@@ -114,6 +114,30 @@ class UsualTest < Minitest::Test
114
114
  assert_equal(Float, doc.class)
115
115
  end
116
116
 
117
+ def test_multi_parse
118
+ p = Oj::Parser.new(:usual)
119
+ out = []
120
+ p.parse('{"a":1}{"b":{"x":2}} {"c":3}') { |j| out.push(j) }
121
+ assert_equal([{'a'=>1}, {'b'=>{'x'=>2}},{'c'=>3}], out)
122
+ end
123
+
124
+ def test_multi_load
125
+ p = Oj::Parser.new(:usual)
126
+ out = []
127
+ r, w = IO.pipe
128
+ thread = Thread.new do
129
+ ['{"a":1}', '{"b":{"x"', ':2}}{"c":', '3}'].each { |seg|
130
+ w.write(seg)
131
+ sleep(0.1)
132
+ }
133
+ w.close
134
+ end
135
+ p.load(r) { |j| out.push(j) }
136
+ r.close
137
+ thread.join
138
+ assert_equal([{'a'=>1}, {'b'=>{'x'=>2}},{'c'=>3}], out)
139
+ end
140
+
117
141
  def test_omit_null
118
142
  p = Oj::Parser.new(:usual)
119
143
  p.omit_null = true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oj
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.16.4
4
+ version: 3.16.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-08 00:00:00.000000000 Z
11
+ date: 2024-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bigdecimal
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ostruct
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0.2'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: minitest
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -308,7 +322,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
308
322
  - !ruby/object:Gem::Version
309
323
  version: '0'
310
324
  requirements: []
311
- rubygems_version: 3.4.10
325
+ rubygems_version: 3.5.11
312
326
  signing_key:
313
327
  specification_version: 4
314
328
  summary: A fast JSON parser and serializer.