yaji 0.3.5 → 0.3.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
  SHA1:
3
- metadata.gz: 0e5f8dae5330310fa8f1990beea4585de902164d
4
- data.tar.gz: 9d331dd0108a45a98dae652314551ddd5f2838a7
3
+ metadata.gz: 4aff4fcf6a87a63e612128d9b4cac2b1a23ef2ac
4
+ data.tar.gz: 42a768aeea6c8b81858b2aecad40d5045c30d649
5
5
  SHA512:
6
- metadata.gz: e83e521a5b33df3f781e858741518e8a9e9182a1c92168ce231e17f46b879a8e287f463109ea84cb4fd3404c9eb4e691b67903fa38291cfd7e21f52051dd59b2
7
- data.tar.gz: 72e2634ae6d164fbdcfe3eab2172d4c7ade3d6d741ba4296fb56cf495a093fe03b8abe920cf6b65d896d60bb5f86766e976bcfac57dc4613d752bab22adb4c00
6
+ metadata.gz: 8ecc72cc3e1177b20eac3312c53a07716361b11f2e8837956b538dc1ecf32103c9a460a1f49fa44d5002111973670911bc817d94b665783e210f718e66daaff1
7
+ data.tar.gz: 04f5db9c5ab40cda59bee33df5cbf434ce2525a2268480780e02208ffed801b7037a1e134ff28335095f01abca905188e80a546205a60d1c5f5b94c5b4d943b1
@@ -1,4 +1,6 @@
1
1
  rvm:
2
- - 1.8.7
3
- - 1.9.2
4
- - 1.9.3
2
+ - 2.0.0
3
+ - 2.1.6
4
+ - 2.2.2
5
+ - 2.3.0
6
+ - 2.4.0
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source 'http://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in ijson.gemspec
3
+ # Specify your gem's dependencies in yaji.gemspec
4
4
  gemspec
@@ -1,3 +1,8 @@
1
+ === 0.3.6 / 2017-01-18
2
+
3
+ * Fix handling empty hashes
4
+ * Build gem for ruby 2.0.0-p645, 2.1.6, 2.2.2, 2.3.0 and 2.4.0
5
+
1
6
  === 0.3.5 / 2014-01-08
2
7
 
3
8
  * Build 64-bit versions for windows
@@ -99,6 +99,7 @@ static int yaji_hash_key(void *ctx, const unsigned char *val, unsigned int len)
99
99
  VALUE key, rv;
100
100
  YAJI_TO_STR((const char *)val, len, key);
101
101
  key = p->symbolize_keys ? ID2SYM(rb_to_id(key)) : key;
102
+ p->empty_hash = 0;
102
103
  if (p->key_in_use) {
103
104
  rb_ary_pop(p->path);
104
105
  } else {
@@ -118,6 +119,7 @@ static int yaji_start_hash(void *ctx)
118
119
  {
119
120
  yaji_parser* p = (yaji_parser*) DATA_PTR(ctx);
120
121
  p->key_in_use = 0;
122
+ p->empty_hash = 1;
121
123
  VALUE rv = rb_ary_new3(3, p->path_str, sym_start_hash, Qnil);
122
124
  rb_ary_push(p->events, rv);
123
125
  return STATUS_CONTINUE;
@@ -126,6 +128,12 @@ static int yaji_start_hash(void *ctx)
126
128
  static int yaji_end_hash(void *ctx)
127
129
  {
128
130
  yaji_parser* p = (yaji_parser*) DATA_PTR(ctx);
131
+ if (p->empty_hash) {
132
+ p->path_str = rb_ary_join(p->path, rb_str_new2("/"));
133
+ VALUE rv = rb_ary_new3(3, p->path_str, sym_end_hash, Qnil);
134
+ rb_ary_push(p->events, rv);
135
+ }
136
+ p->empty_hash = 0;
129
137
  rb_ary_pop(p->path);
130
138
  p->path_str = rb_ary_join(p->path, rb_str_new2("/"));
131
139
  VALUE rv = rb_ary_new3(3, p->path_str, sym_end_hash, Qnil);
@@ -74,6 +74,7 @@ static yajl_callbacks yaji_callbacks = {
74
74
  typedef struct {
75
75
  int symbolize_keys;
76
76
  int key_in_use;
77
+ int empty_hash;
77
78
  int with_path;
78
79
  VALUE input;
79
80
  VALUE rbufsize;
@@ -17,8 +17,8 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require "yaji/version"
21
- require "parser_ext"
20
+ require 'yaji/version'
21
+ require 'parser_ext'
22
22
 
23
23
  module YAJI
24
24
  end
@@ -18,5 +18,5 @@
18
18
  #
19
19
 
20
20
  module YAJI
21
- VERSION = "0.3.5"
21
+ VERSION = '0.3.6'
22
22
  end
@@ -1,16 +1,14 @@
1
1
  gem 'rake-compiler', '>= 0.7.5'
2
- require "rake/extensiontask"
2
+ require 'rake/extensiontask'
3
3
 
4
4
  def gemspec
5
5
  @clean_gemspec ||= eval(File.read(File.expand_path('../../yaji.gemspec', __FILE__)))
6
6
  end
7
7
 
8
8
  require 'rubygems/package_task'
9
- Gem::PackageTask.new(gemspec) do |pkg|
10
- pkg.need_tar = true
11
- end
9
+ Gem::PackageTask.new(gemspec) { |_pkg| }
12
10
 
13
- version_router = lambda do |t|
11
+ version_router = proc do |t|
14
12
  File.open(t.name, 'wb') do |f|
15
13
  f.write <<-RUBY
16
14
  require "yaji/\#{RUBY_VERSION.sub(/\\.\\d+$/, '')}/parser_ext"
@@ -35,46 +33,45 @@ class Platform
35
33
 
36
34
  def short_versions
37
35
  res = []
38
- each_version do |long, short|
36
+ each_version do |_long, short|
39
37
  res << short
40
38
  end
41
39
  res
42
40
  end
43
41
  end
44
42
 
45
- recent = "2.0.0-p353"
46
43
  CROSS_PLATFORMS = [
47
- Platform.new(:name => 'x64-mingw32', :host => 'x86_64-w64-mingw32', :versions => %w(1.9.3-p484 2.0.0-p353 2.1.0)),
48
- Platform.new(:name => 'x86-mingw32', :host => 'i686-w64-mingw32', :versions => %w(1.8.7-p374 1.9.3-p484 2.0.0-p353 2.1.0)),
49
- ]
50
- Rake::ExtensionTask.new("parser_ext", gemspec) do |ext|
44
+ Platform.new(name: 'x64-mingw32', host: 'x86_64-w64-mingw32', versions: %w(2.0.0-p645 2.1.6 2.2.2 2.3.0 2.4.0)),
45
+ Platform.new(name: 'x86-mingw32', host: 'i686-w64-mingw32', versions: %w(2.0.0-p645 2.1.6 2.2.2 2.3.0 2.4.0))
46
+ ].freeze
47
+
48
+ Rake::ExtensionTask.new('parser_ext', gemspec) do |ext|
51
49
  ext.ext_dir = File.join('ext', 'yaji')
52
50
 
53
51
  ext.cross_compile = true
54
52
  ext.cross_platform = ENV['TARGET']
55
- if ENV['RUBY_CC_VERSION']
56
- ext.lib_dir = "lib/yaji"
57
- end
53
+ ext.lib_dir = 'lib/yaji' if ENV['RUBY_CC_VERSION']
58
54
  ext.cross_compiling do |spec|
59
- spec.files.delete("lib/yaji/parser_ext.so")
60
- spec.files.push("lib/parser_ext.rb", Dir["lib/yaji/*/parser_ext.so"])
55
+ spec.files.delete('lib/yaji/parser_ext.so')
56
+ spec.files.push('lib/parser_ext.rb', Dir['lib/yaji/*/parser_ext.so'])
61
57
  file "#{ext.tmp_dir}/#{ext.cross_platform}/stage/lib/parser_ext.rb", &version_router
62
58
  end
63
59
 
64
60
  # clean compiled extension
65
61
  CLEAN.include "#{ext.lib_dir}/*.#{RbConfig::CONFIG['DLEXT']}"
66
62
  end
63
+ CLEAN.include Dir['lib/yaji/*/parser_ext.so']
67
64
 
68
- file "lib/parser_ext.rb", &version_router
69
- task :cross => "lib/parser_ext.rb"
65
+ file 'lib/parser_ext.rb', &version_router
66
+ task cross: 'lib/parser_ext.rb'
70
67
 
71
- desc "Package gem for windows"
72
- task "package:windows" => :package do
68
+ desc 'Package gem for windows'
69
+ task 'package:windows' => :package do
73
70
  CROSS_PLATFORMS.each do |platform|
74
- ENV['TARGET'] = platform.name
75
- platform.each_version do |long, short|
76
- sh("env RUBY_CC_VERSION=#{short} RBENV_VERSION=#{long} rbenv exec rake cross compile")
71
+ platform.each_version do |_long, short|
72
+ sh("TARGET=#{platform.name} RUBY_CC_VERSION=#{short} rake cross compile")
77
73
  end
78
- sh("env RUBY_CC_VERSION=#{platform.short_versions.join(":")} RBENV_VERSION=#{recent} rbenv exec rake cross native gem")
74
+ sh("TARGET=#{platform.name} RUBY_CC_VERSION=#{platform.short_versions.join(':')} rake cross native gem")
75
+ sh('rake clean')
79
76
  end
80
77
  end
@@ -3,7 +3,6 @@ require 'yaji'
3
3
  require 'curb'
4
4
 
5
5
  class TestParser < MiniTest::Unit::TestCase
6
-
7
6
  class Generator
8
7
  def initialize(data, options = {})
9
8
  @callback = nil
@@ -19,9 +18,7 @@ class TestParser < MiniTest::Unit::TestCase
19
18
 
20
19
  def on_body
21
20
  old = @callback
22
- if block_given?
23
- @callback = Proc.new
24
- end
21
+ @callback = Proc.new if block_given?
25
22
  old
26
23
  end
27
24
 
@@ -42,46 +39,46 @@ class TestParser < MiniTest::Unit::TestCase
42
39
  events << [p, e, v]
43
40
  end
44
41
  expected = [
45
- ["", :start_hash, nil],
46
- ["", :hash_key, "total_rows"],
47
- ["/total_rows", :number, 2],
48
- ["", :hash_key, "rows"],
49
- ["/rows", :start_array, nil],
50
- ["/rows/", :start_hash, nil],
51
- ["/rows/", :hash_key, "id"],
52
- ["/rows//id", :string, "buzz"],
53
- ["/rows/", :hash_key, "props"],
54
- ["/rows//props", :start_hash, nil],
55
- ["/rows//props", :hash_key, "humanoid"],
56
- ["/rows//props/humanoid", :boolean, true],
57
- ["/rows//props", :hash_key, "armed"],
58
- ["/rows//props/armed", :boolean, true],
59
- ["/rows//props", :end_hash, nil],
60
- ["/rows/", :hash_key, "movies"],
61
- ["/rows//movies", :start_array, nil],
62
- ["/rows//movies/", :number, 1],
63
- ["/rows//movies/", :number, 2],
64
- ["/rows//movies/", :number, 3],
65
- ["/rows//movies", :end_array, nil],
66
- ["/rows/", :end_hash, nil],
67
- ["/rows/", :start_hash, nil],
68
- ["/rows/", :hash_key, "id"],
69
- ["/rows//id", :string, "barbie"],
70
- ["/rows/", :hash_key, "props"],
71
- ["/rows//props", :start_hash, nil],
72
- ["/rows//props", :hash_key, "humanoid"],
73
- ["/rows//props/humanoid", :boolean, true],
74
- ["/rows//props", :hash_key, "armed"],
75
- ["/rows//props/armed", :boolean, false],
76
- ["/rows//props", :end_hash, nil],
77
- ["/rows/", :hash_key, "movies"],
78
- ["/rows//movies", :start_array, nil],
79
- ["/rows//movies/", :number, 2],
80
- ["/rows//movies/", :number, 3],
81
- ["/rows//movies", :end_array, nil],
82
- ["/rows/", :end_hash, nil],
83
- ["/rows", :end_array, nil],
84
- ["", :end_hash, nil]
42
+ ['', :start_hash, nil],
43
+ ['', :hash_key, 'total_rows'],
44
+ ['/total_rows', :number, 2],
45
+ ['', :hash_key, 'rows'],
46
+ ['/rows', :start_array, nil],
47
+ ['/rows/', :start_hash, nil],
48
+ ['/rows/', :hash_key, 'id'],
49
+ ['/rows//id', :string, 'buzz'],
50
+ ['/rows/', :hash_key, 'props'],
51
+ ['/rows//props', :start_hash, nil],
52
+ ['/rows//props', :hash_key, 'humanoid'],
53
+ ['/rows//props/humanoid', :boolean, true],
54
+ ['/rows//props', :hash_key, 'armed'],
55
+ ['/rows//props/armed', :boolean, true],
56
+ ['/rows//props', :end_hash, nil],
57
+ ['/rows/', :hash_key, 'movies'],
58
+ ['/rows//movies', :start_array, nil],
59
+ ['/rows//movies/', :number, 1],
60
+ ['/rows//movies/', :number, 2],
61
+ ['/rows//movies/', :number, 3],
62
+ ['/rows//movies', :end_array, nil],
63
+ ['/rows/', :end_hash, nil],
64
+ ['/rows/', :start_hash, nil],
65
+ ['/rows/', :hash_key, 'id'],
66
+ ['/rows//id', :string, 'barbie'],
67
+ ['/rows/', :hash_key, 'props'],
68
+ ['/rows//props', :start_hash, nil],
69
+ ['/rows//props', :hash_key, 'humanoid'],
70
+ ['/rows//props/humanoid', :boolean, true],
71
+ ['/rows//props', :hash_key, 'armed'],
72
+ ['/rows//props/armed', :boolean, false],
73
+ ['/rows//props', :end_hash, nil],
74
+ ['/rows/', :hash_key, 'movies'],
75
+ ['/rows//movies', :start_array, nil],
76
+ ['/rows//movies/', :number, 2],
77
+ ['/rows//movies/', :number, 3],
78
+ ['/rows//movies', :end_array, nil],
79
+ ['/rows/', :end_hash, nil],
80
+ ['/rows', :end_array, nil],
81
+ ['', :end_hash, nil]
85
82
  ]
86
83
  assert_equal expected, events
87
84
  end
@@ -89,10 +86,10 @@ class TestParser < MiniTest::Unit::TestCase
89
86
  def test_it_yields_enumerator
90
87
  parser = YAJI::Parser.new('{"hello":"world"}')
91
88
  e = parser.parse
92
- assert_equal ["", :start_hash, nil], e.next
93
- assert_equal ["", :hash_key, "hello"], e.next
94
- assert_equal ["/hello", :string, "world"], e.next
95
- assert_equal ["", :end_hash, nil], e.next
89
+ assert_equal ['', :start_hash, nil], e.next
90
+ assert_equal ['', :hash_key, 'hello'], e.next
91
+ assert_equal ['/hello', :string, 'world'], e.next
92
+ assert_equal ['', :end_hash, nil], e.next
96
93
  assert_raises(StopIteration) { e.next }
97
94
  end
98
95
 
@@ -100,10 +97,10 @@ class TestParser < MiniTest::Unit::TestCase
100
97
  parser = YAJI::Parser.new('{"hello":"world"}', :symbolize_keys => true)
101
98
  e = parser.parse
102
99
  expected = [
103
- ["", :start_hash, nil],
104
- ["", :hash_key, :hello],
105
- ["/hello", :string, "world"],
106
- ["", :end_hash, nil]
100
+ ['', :start_hash, nil],
101
+ ['', :hash_key, :hello],
102
+ ['/hello', :string, 'world'],
103
+ ['', :end_hash, nil]
107
104
  ]
108
105
  assert_equal expected, e.to_a
109
106
  end
@@ -114,17 +111,17 @@ class TestParser < MiniTest::Unit::TestCase
114
111
  parser.each do |o|
115
112
  objects << o
116
113
  end
117
- expected = [{"total_rows" => 2,
118
- "rows" => [
114
+ expected = [{'total_rows' => 2,
115
+ 'rows' => [
119
116
  {
120
- "id" => "buzz",
121
- "props" => { "humanoid"=> true, "armed"=> true },
122
- "movies" => [1,2,3]
117
+ 'id' => 'buzz',
118
+ 'props' => {'humanoid' => true, 'armed' => true},
119
+ 'movies' => [1, 2, 3]
123
120
  },
124
121
  {
125
- "id" => "barbie",
126
- "props" => { "humanoid"=> true, "armed"=> false },
127
- "movies" => [2,3]
122
+ 'id' => 'barbie',
123
+ 'props' => {'humanoid' => true, 'armed' => false},
124
+ 'movies' => [2, 3]
128
125
  }
129
126
  ]}]
130
127
  assert_equal expected, objects
@@ -133,114 +130,138 @@ class TestParser < MiniTest::Unit::TestCase
133
130
  def test_it_yields_whole_array
134
131
  parser = YAJI::Parser.new(toys_json_str)
135
132
  objects = []
136
- parser.each("/rows") do |o|
133
+ parser.each('/rows') do |o|
137
134
  objects << o
138
135
  end
139
- expected = [[{
140
- "id" => "buzz",
141
- "props" => { "humanoid"=> true, "armed"=> true },
142
- "movies" => [1,2,3]
143
- },
144
- {
145
- "id" => "barbie",
146
- "props" => { "humanoid"=> true, "armed"=> false },
147
- "movies" => [2,3]
148
- }]]
136
+ expected = [
137
+ [
138
+ {
139
+ 'id' => 'buzz',
140
+ 'props' => {'humanoid' => true, 'armed' => true},
141
+ 'movies' => [1, 2, 3]
142
+ },
143
+ {
144
+ 'id' => 'barbie',
145
+ 'props' => {'humanoid' => true, 'armed' => false},
146
+ 'movies' => [2, 3]
147
+ }
148
+ ]
149
+ ]
149
150
  assert_equal expected, objects
150
151
  end
151
152
 
152
153
  def test_it_yeilds_array_contents_row_by_row
153
154
  parser = YAJI::Parser.new(toys_json_str)
154
155
  objects = []
155
- parser.each("/rows/") do |o|
156
+ parser.each('/rows/') do |o|
156
157
  objects << o
157
158
  end
158
- expected = [{
159
- "id" => "buzz",
160
- "props" => { "humanoid"=> true, "armed"=> true },
161
- "movies" => [1,2,3]
162
- },
163
- {
164
- "id" => "barbie",
165
- "props" => { "humanoid"=> true, "armed"=> false },
166
- "movies" => [2,3]
167
- }]
159
+ expected = [
160
+ {
161
+ 'id' => 'buzz',
162
+ 'props' => {'humanoid' => true, 'armed' => true},
163
+ 'movies' => [1, 2, 3]
164
+ },
165
+ {
166
+ 'id' => 'barbie',
167
+ 'props' => {'humanoid' => true, 'armed' => false},
168
+ 'movies' => [2, 3]
169
+ }
170
+ ]
168
171
  assert_equal expected, objects
169
172
  end
170
173
 
171
174
  def test_it_could_curb_async_approach
172
- curl = Curl::Easy.new('http://avsej.net/test.json')
175
+ curl = Curl::Easy.new('https://avsej.net/test.json')
173
176
  parser = YAJI::Parser.new(curl)
174
177
  object = parser.each.to_a.first
175
- expected = {"foo"=>"bar", "baz"=>{"nums"=>[42, 3.1415]}}
178
+ expected = {'foo' => 'bar', 'baz' => {'nums' => [42, 3.1415]}}
176
179
  assert_equal expected, object
177
180
  end
178
181
 
179
182
  def test_it_allow_several_selectors
180
183
  parser = YAJI::Parser.new(toys_json_str)
181
184
  objects = []
182
- parser.each(["/total_rows", "/rows/"]) do |o|
185
+ parser.each(['/total_rows', '/rows/']) do |o|
183
186
  objects << o
184
187
  end
185
- expected = [2,
186
- {
187
- "id" => "buzz",
188
- "props" => { "humanoid"=> true, "armed"=> true },
189
- "movies" => [1,2,3]
190
- },
191
- {
192
- "id" => "barbie",
193
- "props" => { "humanoid"=> true, "armed"=> false },
194
- "movies" => [2,3]
195
- }]
188
+ expected = [
189
+ 2,
190
+ {
191
+ 'id' => 'buzz',
192
+ 'props' => {'humanoid' => true, 'armed' => true},
193
+ 'movies' => [1, 2, 3]
194
+ },
195
+ {
196
+ 'id' => 'barbie',
197
+ 'props' => {'humanoid' => true, 'armed' => false},
198
+ 'movies' => [2, 3]
199
+ }
200
+ ]
196
201
  assert_equal expected, objects
197
202
  end
198
203
 
199
204
  def test_it_optionally_yields_object_path
200
205
  parser = YAJI::Parser.new(toys_json_str)
201
206
  objects = []
202
- parser.each(["/total_rows", "/rows/"], :with_path => true) do |o|
207
+ parser.each(['/total_rows', '/rows/'], :with_path => true) do |o|
203
208
  objects << o
204
209
  end
205
- expected = [["/total_rows", 2],
206
- ["/rows/", {
207
- "id" => "buzz",
208
- "props" => { "humanoid"=> true, "armed"=> true },
209
- "movies" => [1,2,3]
210
- }],
211
- ["/rows/", {
212
- "id" => "barbie",
213
- "props" => { "humanoid"=> true, "armed"=> false },
214
- "movies" => [2,3]
215
- }]]
210
+ expected = [
211
+ ['/total_rows', 2],
212
+ [
213
+ '/rows/',
214
+ {
215
+ 'id' => 'buzz',
216
+ 'props' => {'humanoid' => true, 'armed' => true},
217
+ 'movies' => [1, 2, 3]
218
+ }
219
+ ],
220
+ [
221
+ '/rows/',
222
+ {
223
+ 'id' => 'barbie',
224
+ 'props' => {'humanoid' => true, 'armed' => false},
225
+ 'movies' => [2, 3]
226
+ }
227
+ ]
228
+ ]
216
229
  assert_equal expected, objects
217
230
  end
218
231
 
219
232
  def test_it_allows_to_specify_filter_and_options_at_initialization
220
233
  parser = YAJI::Parser.new(toys_json_str,
221
- :filter => ["/total_rows", "/rows/"],
234
+ :filter => ['/total_rows', '/rows/'],
222
235
  :with_path => true)
223
236
  objects = []
224
237
  parser.each do |o|
225
238
  objects << o
226
239
  end
227
- expected = [["/total_rows", 2],
228
- ["/rows/", {
229
- "id" => "buzz",
230
- "props" => { "humanoid"=> true, "armed"=> true },
231
- "movies" => [1,2,3]
232
- }],
233
- ["/rows/", {
234
- "id" => "barbie",
235
- "props" => { "humanoid"=> true, "armed"=> false },
236
- "movies" => [2,3]
237
- }]]
240
+ expected = [
241
+ ['/total_rows', 2],
242
+ [
243
+ '/rows/',
244
+ {
245
+ 'id' => 'buzz',
246
+ 'props' => {'humanoid' => true, 'armed' => true},
247
+ 'movies' => [1, 2, 3]
248
+ }
249
+ ],
250
+ [
251
+ '/rows/',
252
+ {
253
+ 'id' => 'barbie',
254
+ 'props' => {'humanoid' => true, 'armed' => false},
255
+ 'movies' => [2, 3]
256
+ }
257
+ ]
258
+ ]
238
259
  assert_equal expected, objects
239
260
  end
240
261
 
241
262
  def test_it_doesnt_raise_exception_on_empty_input
242
- YAJI::Parser.new("").parse
243
- YAJI::Parser.new(" ").parse
263
+ YAJI::Parser.new('').parse
264
+ YAJI::Parser.new(' ').parse
244
265
  YAJI::Parser.new("\n").parse
245
266
  YAJI::Parser.new(" \n\n ").parse
246
267
  end
@@ -257,7 +278,7 @@ class TestParser < MiniTest::Unit::TestCase
257
278
  parser.parse
258
279
  end
259
280
  assert_raises(ArgumentError) do
260
- parser.each{|x| }
281
+ parser.each { |_x| }
261
282
  end
262
283
  end
263
284
 
@@ -305,22 +326,24 @@ class TestParser < MiniTest::Unit::TestCase
305
326
  JSON
306
327
  parser << data
307
328
 
308
- expected = [{
309
- "id" => "buzz",
310
- "props" => { "humanoid"=> true, "armed"=> true },
311
- "movies" => [1,2,3]
312
- },
313
- {
314
- "id" => "barbie",
315
- "props" => { "humanoid"=> true, "armed"=> false },
316
- "movies" => [2,3]
317
- }]
329
+ expected = [
330
+ {
331
+ 'id' => 'buzz',
332
+ 'props' => {'humanoid' => true, 'armed' => true},
333
+ 'movies' => [1, 2, 3]
334
+ },
335
+ {
336
+ 'id' => 'barbie',
337
+ 'props' => {'humanoid' => true, 'armed' => false},
338
+ 'movies' => [2, 3]
339
+ }
340
+ ]
318
341
  assert_equal expected, objects
319
342
  end
320
343
 
321
344
  def test_it_parses_chunked_data
322
345
  generator = Generator.new(['{"total_rows":', '0,"offset":0,"rows":[]', '}'])
323
- iter = YAJI::Parser.new(generator).each(["total_rows", "/rows/", "/errors/"], :with_path => true)
346
+ iter = YAJI::Parser.new(generator).each(['total_rows', '/rows/', '/errors/'], :with_path => true)
324
347
  begin
325
348
  loop do
326
349
  iter.next
@@ -331,7 +354,7 @@ class TestParser < MiniTest::Unit::TestCase
331
354
 
332
355
  def test_it_skips_empty_chunks
333
356
  generator = Generator.new(['{"total_rows":', '0,"offset":0,"rows":[]', '}', '', nil])
334
- iter = YAJI::Parser.new(generator).each(["total_rows", "/rows/", "/errors/"], :with_path => true)
357
+ iter = YAJI::Parser.new(generator).each(['total_rows', '/rows/', '/errors/'], :with_path => true)
335
358
  begin
336
359
  loop do
337
360
  iter.next
@@ -340,6 +363,23 @@ class TestParser < MiniTest::Unit::TestCase
340
363
  end
341
364
  end
342
365
 
366
+ def test_it_correctly_handles_empty_hashes
367
+ chunks = ['{"rows":[{"value":{}}]}']
368
+
369
+ parser = YAJI::Parser.new(:filter => '/rows/')
370
+
371
+ objects = []
372
+ parser.on_object do |obj|
373
+ objects << obj
374
+ end
375
+
376
+ chunks.each do |chunk|
377
+ parser.write(chunk)
378
+ end
379
+
380
+ assert_equal 1, objects.size
381
+ end
382
+
343
383
  protected
344
384
 
345
385
  def toys_json_str
@@ -1,24 +1,25 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "yaji/version"
2
+
3
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
4
+ require 'yaji/version'
4
5
 
5
6
  Gem::Specification.new do |s|
6
- s.name = "yaji"
7
+ s.name = 'yaji'
7
8
  s.version = YAJI::VERSION
8
9
  s.author = 'Couchbase'
9
10
  s.email = 'info@couchbase.com'
10
11
  s.license = 'ASL-2'
11
- s.homepage = "https://github.com/avsej/yaji"
12
- s.summary = %q{Yet another JSON iterator}
13
- s.description = %q{YAJI is a ruby wrapper to YAJL providing iterator interface to streaming JSON parser}
12
+ s.homepage = 'https://github.com/avsej/yaji'
13
+ s.summary = 'Yet another JSON iterator'
14
+ s.description = 'YAJI is a ruby wrapper to YAJL providing iterator interface to streaming JSON parser'
14
15
 
15
- s.rubyforge_project = "yaji"
16
+ s.rubyforge_project = 'yaji'
16
17
 
17
18
  s.files = `git ls-files`.split("\n")
18
19
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
20
21
  s.extensions = `git ls-files -- ext/**/extconf.rb`.split("\n")
21
- s.require_paths = ["lib"]
22
+ s.require_paths = ['lib']
22
23
 
23
24
  s.add_development_dependency 'rake'
24
25
  s.add_development_dependency 'rake-compiler'
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaji
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Couchbase
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-08 00:00:00.000000000 Z
11
+ date: 2017-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake-compiler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: curb
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: YAJI is a ruby wrapper to YAJL providing iterator interface to streaming
@@ -74,8 +74,8 @@ extensions:
74
74
  - ext/yaji/extconf.rb
75
75
  extra_rdoc_files: []
76
76
  files:
77
- - .gitignore
78
- - .travis.yml
77
+ - ".gitignore"
78
+ - ".travis.yml"
79
79
  - Gemfile
80
80
  - HISTORY.markdown
81
81
  - LICENSE
@@ -120,20 +120,18 @@ require_paths:
120
120
  - lib
121
121
  required_ruby_version: !ruby/object:Gem::Requirement
122
122
  requirements:
123
- - - '>='
123
+ - - ">="
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  requirements:
128
- - - '>='
128
+ - - ">="
129
129
  - !ruby/object:Gem::Version
130
130
  version: '0'
131
131
  requirements: []
132
132
  rubyforge_project: yaji
133
- rubygems_version: 2.0.14
133
+ rubygems_version: 2.6.8
134
134
  signing_key:
135
135
  specification_version: 4
136
136
  summary: Yet another JSON iterator
137
- test_files:
138
- - test/fixture.json
139
- - test/test_parser.rb
137
+ test_files: []