yaji 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.markdown CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.0.9 / 2011-09-01
2
+
3
+ * Optionally yield path in object iterator
4
+
1
5
  === 0.0.8 / 2011-08-30
2
6
 
3
7
  * Use rb_str_new2 for backward comatibility with ruby 1.8.x
@@ -296,6 +296,7 @@ static VALUE rb_yaji_each_iter(VALUE chunk, VALUE* params_p)
296
296
  VALUE proc = params[0];
297
297
  VALUE stack = params[1];
298
298
  VALUE query = params[2];
299
+ VALUE with_path = params[3];
299
300
  VALUE last_entry, object, container, key, hash;
300
301
 
301
302
  if (NIL_P(query) || rb_yaji_str_start_with(path, query)) {
@@ -317,7 +318,11 @@ static VALUE rb_yaji_each_iter(VALUE chunk, VALUE* params_p)
317
318
  } else if (event == sym_end_hash || event == sym_end_array) {
318
319
  object = rb_ary_pop(stack);
319
320
  if (RARRAY_LEN(stack) == 0) {
320
- rb_funcall(proc, id_call, 1, object);
321
+ if (with_path == Qnil || with_path == Qfalse) {
322
+ rb_funcall(proc, id_call, 1, object);
323
+ } else {
324
+ rb_funcall(proc, id_call, 1, rb_ary_new3(2, path, object));
325
+ }
321
326
  }
322
327
  } else {
323
328
  last_entry = rb_ary_entry(stack, -1);
@@ -331,7 +336,11 @@ static VALUE rb_yaji_each_iter(VALUE chunk, VALUE* params_p)
331
336
  rb_ary_push(last_entry, value);
332
337
  break;
333
338
  case T_NIL:
334
- rb_funcall(proc, id_call, 1, value);
339
+ if (with_path == Qnil || with_path == Qfalse) {
340
+ rb_funcall(proc, id_call, 1, value);
341
+ } else {
342
+ rb_funcall(proc, id_call, 1, rb_ary_new3(2, path, value));
343
+ }
335
344
  break;
336
345
  }
337
346
  }
@@ -341,12 +350,18 @@ static VALUE rb_yaji_each_iter(VALUE chunk, VALUE* params_p)
341
350
 
342
351
  static VALUE rb_yaji_parser_each(int argc, VALUE* argv, VALUE self)
343
352
  {
344
- VALUE query, proc, params[3];
345
- rb_scan_args(argc, argv, "01&", &query, &proc);
353
+ VALUE query, proc, options, params[4];
346
354
  RETURN_ENUMERATOR(self, argc, argv);
355
+ rb_scan_args(argc, argv, "02&", &query, &options, &proc);
347
356
  params[0] = proc; // callback
348
357
  params[1] = rb_ary_new(); // stack
349
358
  params[2] = query;
359
+ if (options != Qnil) {
360
+ Check_Type(options, T_HASH);
361
+ params[3] = rb_hash_aref(options, sym_with_path);
362
+ } else {
363
+ params[3] = Qnil;
364
+ }
350
365
  rb_block_call(self, id_parse, 0, NULL, rb_yaji_each_iter, (VALUE)params);
351
366
  return Qnil;
352
367
  }
@@ -401,6 +416,7 @@ void Init_parser_ext() {
401
416
  sym_check_utf8 = ID2SYM(rb_intern("check_utf8"));
402
417
  sym_symbolize_keys = ID2SYM(rb_intern("symbolize_keys"));
403
418
  sym_read_buffer_size = ID2SYM(rb_intern("read_buffer_size"));
419
+ sym_with_path = ID2SYM(rb_intern("with_path"));
404
420
  sym_null = ID2SYM(rb_intern("null"));
405
421
  sym_boolean = ID2SYM(rb_intern("boolean"));
406
422
  sym_number = ID2SYM(rb_intern("number"));
@@ -42,7 +42,7 @@ static rb_encoding *utf8_encoding;
42
42
  static VALUE m_yaji, c_yaji_parser, c_parse_error, c_stringio;
43
43
 
44
44
  static ID id_call, id_read, id_parse, id_perform, id_on_body, id_bytesize, id_strip;
45
- static ID sym_allow_comments, sym_check_utf8, sym_symbolize_keys,
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,
48
48
  sym_end_array;
data/lib/yaji/version.rb CHANGED
@@ -18,5 +18,5 @@
18
18
  #
19
19
 
20
20
  module YAJI
21
- VERSION = "0.0.8"
21
+ VERSION = "0.0.9"
22
22
  end
data/test/test_parser.rb CHANGED
@@ -165,6 +165,26 @@ class TestParser < MiniTest::Unit::TestCase
165
165
  assert_equal expected, objects
166
166
  end
167
167
 
168
+ def test_it_optionally_yeilds_object_path
169
+ parser = YAJI::Parser.new(toys_json_str)
170
+ objects = []
171
+ parser.each(["total_rows", "rows/"], :with_path => true) do |o|
172
+ objects << o
173
+ end
174
+ expected = [["total_rows", 2],
175
+ ["rows/", {
176
+ "id" => "buzz",
177
+ "props" => { "humanoid"=> true, "armed"=> true },
178
+ "movies" => [1,2,3]
179
+ }],
180
+ ["rows/", {
181
+ "id" => "barbie",
182
+ "props" => { "humanoid"=> true, "armed"=> false },
183
+ "movies" => [2,3]
184
+ }]]
185
+ assert_equal expected, objects
186
+ end
187
+
168
188
  def test_it_doesnt_raise_exception_on_empty_input
169
189
  YAJI::Parser.new("").parse
170
190
  YAJI::Parser.new(" ").parse
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.0.8
4
+ version: 0.0.9
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-08-30 00:00:00.000000000Z
12
+ date: 2011-09-01 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake-compiler
16
- requirement: &11061180 !ruby/object:Gem::Requirement
16
+ requirement: &13939240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *11061180
24
+ version_requirements: *13939240
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: minitest
27
- requirement: &11060740 !ruby/object:Gem::Requirement
27
+ requirement: &13938660 !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: *11060740
35
+ version_requirements: *13938660
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: curb
38
- requirement: &11060320 !ruby/object:Gem::Requirement
38
+ requirement: &13938080 !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: *11060320
46
+ version_requirements: *13938080
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: ruby-debug19
49
- requirement: &11059800 !ruby/object:Gem::Requirement
49
+ requirement: &13937360 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *11059800
57
+ version_requirements: *13937360
58
58
  description: YAJI is a ruby wrapper to YAJL providing iterator interface to streaming
59
59
  JSON parser
60
60
  email: info@couchbase.com
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  version: '0'
120
120
  requirements: []
121
121
  rubyforge_project: yaji
122
- rubygems_version: 1.8.6
122
+ rubygems_version: 1.8.7
123
123
  signing_key:
124
124
  specification_version: 3
125
125
  summary: Yet another JSON iterator