yaji 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
data/HISTORY.markdown CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.1.0 / 2011-12-12
2
+
3
+ * Skip empty and nil chunks
4
+
1
5
  === 0.0.9 / 2011-09-01
2
6
 
3
7
  * Optionally yield path in object iterator
data/README.markdown CHANGED
@@ -2,6 +2,7 @@ Yet another JSON iterator
2
2
  =========================
3
3
 
4
4
  YAJI is a ruby wrapper to YAJL providing iterator interface to streaming JSON parser.
5
+ [![Build Status](https://secure.travis-ci.org/avsej/yaji.png)](http://travis-ci.org/avsej/yaji)
5
6
 
6
7
  INSTALL
7
8
  -------
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
1
  require "bundler/gem_tasks"
2
2
  Dir['tasks/*.rake'].sort.each { |f| load f }
3
3
 
4
+ task :default => [:clean, :compile, :test]
@@ -160,10 +160,14 @@ static VALUE rb_yaji_parser_parse_chunk(VALUE chunk, VALUE self)
160
160
  {
161
161
  yajl_status rc;
162
162
  yaji_parser* p = (yaji_parser*) DATA_PTR(self);
163
- const char* buf = RSTRING_PTR(chunk);
164
- unsigned int len = RSTRING_LEN(chunk);
163
+ const char* buf;
164
+ unsigned int len;
165
165
  int i;
166
166
 
167
+ if (NIL_P(chunk) || (len = RSTRING_LEN(chunk)) == 0) {
168
+ return INT2FIX(0);
169
+ }
170
+ buf = RSTRING_PTR(chunk);
167
171
  p->events = rb_ary_new();
168
172
  p->chunk = chunk;
169
173
  rc = yajl_parse(p->handle, (const unsigned char*)buf, len);
data/lib/yaji/version.rb CHANGED
@@ -18,5 +18,5 @@
18
18
  #
19
19
 
20
20
  module YAJI
21
- VERSION = "0.0.9"
21
+ VERSION = "0.0.10"
22
22
  end
data/test/test_parser.rb CHANGED
@@ -4,6 +4,37 @@ require 'curb'
4
4
 
5
5
  class TestParser < MiniTest::Unit::TestCase
6
6
 
7
+ class Generator
8
+ def initialize(data, options = {})
9
+ @callback = nil
10
+ @options = {:chunk_size => 10}.merge(options)
11
+ @chunks = case data
12
+ when Array
13
+ data
14
+ when String
15
+ count = (data.bytesize / @options[:chunk_size].to_f).ceil
16
+ data.unpack("a#{@options[:chunk_size]}" * count)
17
+ end
18
+ end
19
+
20
+ def on_body
21
+ old = @callback
22
+ if block_given?
23
+ @callback = Proc.new
24
+ end
25
+ old
26
+ end
27
+
28
+ def perform
29
+ size = @options[:chunk_size]
30
+ if @callback
31
+ @chunks.each do |chunk|
32
+ @callback.call(chunk)
33
+ end
34
+ end
35
+ end
36
+ end
37
+
7
38
  def test_it_generates_events
8
39
  events = []
9
40
  parser = YAJI::Parser.new(toys_json_str)
@@ -192,6 +223,28 @@ class TestParser < MiniTest::Unit::TestCase
192
223
  YAJI::Parser.new(" \n\n ").parse
193
224
  end
194
225
 
226
+ def test_it_parses_chunked_data
227
+ generator = Generator.new(['{"total_rows":', '0,"offset":0,"rows":[]', '}'])
228
+ iter = YAJI::Parser.new(generator).each(["total_rows", "rows/", "errors/"], :with_path => true)
229
+ begin
230
+ loop do
231
+ iter.next
232
+ end
233
+ rescue StopIteration
234
+ end
235
+ end
236
+
237
+ def test_it_skips_empty_chunks
238
+ generator = Generator.new(['{"total_rows":', '0,"offset":0,"rows":[]', '}', '', nil])
239
+ iter = YAJI::Parser.new(generator).each(["total_rows", "rows/", "errors/"], :with_path => true)
240
+ begin
241
+ loop do
242
+ iter.next
243
+ end
244
+ rescue StopIteration
245
+ end
246
+ end
247
+
195
248
  protected
196
249
 
197
250
  def toys_json_str
data/yaji.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.extensions = `git ls-files -- ext/**/extconf.rb`.split("\n")
21
21
  s.require_paths = ["lib"]
22
22
 
23
+ s.add_development_dependency 'rake', '0.8.7'
23
24
  s.add_development_dependency 'rake-compiler'
24
25
  s.add_development_dependency 'minitest'
25
26
  s.add_development_dependency 'curb'
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.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-01 00:00:00.000000000Z
12
+ date: 2011-12-12 00:00:00.000000000Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &15274560 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - =
20
+ - !ruby/object:Gem::Version
21
+ version: 0.8.7
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *15274560
14
25
  - !ruby/object:Gem::Dependency
15
26
  name: rake-compiler
16
- requirement: &13939240 !ruby/object:Gem::Requirement
27
+ requirement: &15274160 !ruby/object:Gem::Requirement
17
28
  none: false
18
29
  requirements:
19
30
  - - ! '>='
@@ -21,10 +32,10 @@ dependencies:
21
32
  version: '0'
22
33
  type: :development
23
34
  prerelease: false
24
- version_requirements: *13939240
35
+ version_requirements: *15274160
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: minitest
27
- requirement: &13938660 !ruby/object:Gem::Requirement
38
+ requirement: &15273700 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ! '>='
@@ -32,10 +43,10 @@ dependencies:
32
43
  version: '0'
33
44
  type: :development
34
45
  prerelease: false
35
- version_requirements: *13938660
46
+ version_requirements: *15273700
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: curb
38
- requirement: &13938080 !ruby/object:Gem::Requirement
49
+ requirement: &15273280 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ! '>='
@@ -43,10 +54,10 @@ dependencies:
43
54
  version: '0'
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *13938080
57
+ version_requirements: *15273280
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: ruby-debug19
49
- requirement: &13937360 !ruby/object:Gem::Requirement
60
+ requirement: &15272820 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ! '>='
@@ -54,7 +65,7 @@ dependencies:
54
65
  version: '0'
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *13937360
68
+ version_requirements: *15272820
58
69
  description: YAJI is a ruby wrapper to YAJL providing iterator interface to streaming
59
70
  JSON parser
60
71
  email: info@couchbase.com
@@ -64,6 +75,7 @@ extensions:
64
75
  extra_rdoc_files: []
65
76
  files:
66
77
  - .gitignore
78
+ - .travis.yml
67
79
  - Gemfile
68
80
  - HISTORY.markdown
69
81
  - LICENSE
@@ -119,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
131
  version: '0'
120
132
  requirements: []
121
133
  rubyforge_project: yaji
122
- rubygems_version: 1.8.7
134
+ rubygems_version: 1.8.10
123
135
  signing_key:
124
136
  specification_version: 3
125
137
  summary: Yet another JSON iterator