yaji 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ === 0.2.0 / 2012-01-12
2
+
3
+ * Fix root element (broken backward compatibility, see tests)
4
+ * Close input when work is done
5
+
1
6
  === 0.1.2 / 2011-12-13
2
7
 
3
8
  * Finish yajl API hiding
@@ -242,6 +242,7 @@ static VALUE rb_yaji_parser_parse(int argc, VALUE* argv, VALUE self)
242
242
  RETURN_ENUMERATOR(self, argc, argv);
243
243
 
244
244
  p->path = rb_ary_new();
245
+ rb_ary_push(p->path, rb_str_new("", 0));
245
246
  p->path_str = rb_str_new("", 0);
246
247
  p->chunk = Qnil;
247
248
 
@@ -265,6 +266,9 @@ static VALUE rb_yaji_parser_parse(int argc, VALUE* argv, VALUE self)
265
266
  rb_funcall(p->parser_cb, id_call, 1, RARRAY_PTR(p->events)[i]);
266
267
  }
267
268
 
269
+ if (rb_respond_to(p->input, id_close)) {
270
+ rb_funcall(p->input, id_close, 0);
271
+ }
268
272
  return Qnil;
269
273
  }
270
274
 
@@ -409,6 +413,7 @@ void Init_parser_ext() {
409
413
  rb_define_method(c_yaji_parser, "each", rb_yaji_parser_each, -1);
410
414
 
411
415
  id_call = rb_intern("call");
416
+ id_close = rb_intern("close");
412
417
  id_read = rb_intern("read");
413
418
  id_parse = rb_intern("parse");
414
419
  id_strip = rb_intern("strip");
@@ -41,7 +41,7 @@ static rb_encoding *utf8_encoding;
41
41
 
42
42
  static VALUE m_yaji, c_yaji_parser, c_parse_error, c_stringio;
43
43
 
44
- static ID id_call, id_read, id_parse, id_perform, id_on_body, id_bytesize, id_strip;
44
+ static ID id_call, id_close, id_read, id_parse, id_perform, id_on_body, id_bytesize, id_strip;
45
45
  static ID sym_allow_comments, sym_check_utf8, sym_symbolize_keys, sym_with_path,
46
46
  sym_read_buffer_size, sym_null, sym_boolean, sym_number, sym_string,
47
47
  sym_hash_key, sym_start_hash, sym_end_hash, sym_start_array,
@@ -18,5 +18,5 @@
18
18
  #
19
19
 
20
20
  module YAJI
21
- VERSION = "0.1.2"
21
+ VERSION = "0.2.0"
22
22
  end
@@ -42,46 +42,46 @@ class TestParser < MiniTest::Unit::TestCase
42
42
  events << [p, e, v]
43
43
  end
44
44
  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]
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]
85
85
  ]
86
86
  assert_equal expected, events
87
87
  end
@@ -91,7 +91,7 @@ class TestParser < MiniTest::Unit::TestCase
91
91
  e = parser.parse
92
92
  assert_equal ["", :start_hash, nil], e.next
93
93
  assert_equal ["", :hash_key, "hello"], e.next
94
- assert_equal ["hello", :string, "world"], e.next
94
+ assert_equal ["/hello", :string, "world"], e.next
95
95
  assert_equal ["", :end_hash, nil], e.next
96
96
  assert_raises(StopIteration) { e.next }
97
97
  end
@@ -102,7 +102,7 @@ class TestParser < MiniTest::Unit::TestCase
102
102
  expected = [
103
103
  ["", :start_hash, nil],
104
104
  ["", :hash_key, :hello],
105
- ["hello", :string, "world"],
105
+ ["/hello", :string, "world"],
106
106
  ["", :end_hash, nil]
107
107
  ]
108
108
  assert_equal expected, e.to_a
@@ -133,7 +133,7 @@ class TestParser < MiniTest::Unit::TestCase
133
133
  def test_it_yields_whole_array
134
134
  parser = YAJI::Parser.new(toys_json_str)
135
135
  objects = []
136
- parser.each("rows") do |o|
136
+ parser.each("/rows") do |o|
137
137
  objects << o
138
138
  end
139
139
  expected = [[{
@@ -152,7 +152,7 @@ class TestParser < MiniTest::Unit::TestCase
152
152
  def test_it_yeilds_array_contents_row_by_row
153
153
  parser = YAJI::Parser.new(toys_json_str)
154
154
  objects = []
155
- parser.each("rows/") do |o|
155
+ parser.each("/rows/") do |o|
156
156
  objects << o
157
157
  end
158
158
  expected = [{
@@ -179,7 +179,7 @@ class TestParser < MiniTest::Unit::TestCase
179
179
  def test_it_allow_several_selectors
180
180
  parser = YAJI::Parser.new(toys_json_str)
181
181
  objects = []
182
- parser.each(["total_rows", "rows/"]) do |o|
182
+ parser.each(["/total_rows", "/rows/"]) do |o|
183
183
  objects << o
184
184
  end
185
185
  expected = [2,
@@ -199,16 +199,16 @@ class TestParser < MiniTest::Unit::TestCase
199
199
  def test_it_optionally_yeilds_object_path
200
200
  parser = YAJI::Parser.new(toys_json_str)
201
201
  objects = []
202
- parser.each(["total_rows", "rows/"], :with_path => true) do |o|
202
+ parser.each(["/total_rows", "/rows/"], :with_path => true) do |o|
203
203
  objects << o
204
204
  end
205
- expected = [["total_rows", 2],
206
- ["rows/", {
205
+ expected = [["/total_rows", 2],
206
+ ["/rows/", {
207
207
  "id" => "buzz",
208
208
  "props" => { "humanoid"=> true, "armed"=> true },
209
209
  "movies" => [1,2,3]
210
210
  }],
211
- ["rows/", {
211
+ ["/rows/", {
212
212
  "id" => "barbie",
213
213
  "props" => { "humanoid"=> true, "armed"=> false },
214
214
  "movies" => [2,3]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaji
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-13 00:00:00.000000000Z
12
+ date: 2012-01-12 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &12907280 !ruby/object:Gem::Requirement
16
+ requirement: &23267520 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - =
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.8.7
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *12907280
24
+ version_requirements: *23267520
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake-compiler
27
- requirement: &12906880 !ruby/object:Gem::Requirement
27
+ requirement: &23267120 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *12906880
35
+ version_requirements: *23267120
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: minitest
38
- requirement: &12906420 !ruby/object:Gem::Requirement
38
+ requirement: &23266660 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *12906420
46
+ version_requirements: *23266660
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: curb
49
- requirement: &12906000 !ruby/object:Gem::Requirement
49
+ requirement: &23266240 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *12906000
57
+ version_requirements: *23266240
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: ruby-debug19
60
- requirement: &12905540 !ruby/object:Gem::Requirement
60
+ requirement: &23265780 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *12905540
68
+ version_requirements: *23265780
69
69
  description: YAJI is a ruby wrapper to YAJL providing iterator interface to streaming
70
70
  JSON parser
71
71
  email: info@couchbase.com
@@ -138,3 +138,4 @@ summary: Yet another JSON iterator
138
138
  test_files:
139
139
  - test/fixture.json
140
140
  - test/test_parser.rb
141
+ has_rdoc: