json-streamer 1.0.0 → 1.1.0

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: 78f558defb01fa6c47525de0c47a96900638168d
4
- data.tar.gz: ea21aadfedf4d8c9dddb1e8f06a0c2d9aff44be4
3
+ metadata.gz: defb27980ce9856c197b03d9dcd036c6a9676faf
4
+ data.tar.gz: be55ab586714595baab1ae9e570fc5c0d1c869d9
5
5
  SHA512:
6
- metadata.gz: a595fd7837371e1555180e17beaf42e2bcac4dd06aa12973393431dd234d4eb71f2ba6ffa6df6b965a00e40837295b33409b9d3840cb23d32039e658fd6f94b1
7
- data.tar.gz: 144ef35ae0f18f2fb51099e735f87dc39a17a1da734f35575ef27fd3dff0f01e7054f765a5b852aca9f1176dc65e9ca3a6210f89eb8a1c47270cc9df4838d645
6
+ metadata.gz: ccefc6735d211f77a1cd1c18b05073d0d585033478f8495a922402dbf8c479b9f9eb3804a53c55c6f5b21b6dc8c93873ab9a569df97e95daefd5d04e24a9432d
7
+ data.tar.gz: c132b1c90100166e7716959b12fa085e64ebfaa754fcfc919e20c290537704d1e915632846ae680b697fe3a29adefafdd751e1cc79ae6685b510da6c9d6801a2
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  .idea/*
11
+ *.iml
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Json::Streamer
2
2
 
3
- | Build status | |
4
- | ------------ | - |
3
+ #### Ruby utility that supports JSON streaming allowing you to get data based on various criteria (key, nesting level, etc).
4
+
5
+ | Branch | Build status |
6
+ | ------ | ------------ |
5
7
  | Release | [![Build Status](https://travis-ci.org/thisismydesign/json-streamer.svg?branch=release)](https://travis-ci.org/thisismydesign/json-streamer) [![Coverage Status](https://coveralls.io/repos/github/thisismydesign/json-streamer/badge.svg?branch=release)](https://coveralls.io/github/thisismydesign/json-streamer?branch=release) [![Gem Version](https://badge.fury.io/rb/json-streamer.svg)](https://badge.fury.io/rb/json-streamer) |
6
8
  | Development | [![Build Status](https://travis-ci.org/thisismydesign/json-streamer.svg?branch=master)](https://travis-ci.org/thisismydesign/json-streamer) [![Coverage Status](https://coveralls.io/repos/github/thisismydesign/json-streamer/badge.svg?branch=master)](https://coveralls.io/github/thisismydesign/json-streamer?branch=master) |
7
9
 
8
- Ruby utility that supports JSON streaming allowing you to get data based on various criteria (key, nesting level, etc).
9
-
10
10
  *If you've tried JSON streaming with other Ruby libraries before (e.g. [JSON::Stream](https://github.com/dgraham/json-stream), [Yajl::FFI](https://github.com/dgraham/yajl-ffi)):*
11
11
 
12
12
  This gem will basically spare you the need to define your own callbacks (i.e. implement an actual JSON parser using `start_object`, `end_object`, `key`, `value`, etc.).
@@ -130,6 +130,26 @@ Output:
130
130
  {}
131
131
  ```
132
132
 
133
+ #### EventMachine-style input (since 1.1.0)
134
+
135
+ ```ruby
136
+ # Get a JsonStreamer object that provides access to the parser
137
+ # but does not start processing immediately
138
+ streamer = Json::Streamer::JsonStreamer.new
139
+
140
+ streamer.get(nesting_level:1) do |object|
141
+ p object
142
+ end
143
+ ```
144
+
145
+ Then later in your EventMachine handler:
146
+
147
+ ```ruby
148
+ def receive_data(data)
149
+ streamer.parser << data
150
+ end
151
+ ```
152
+
133
153
  Check the unit tests for more examples ([spec/streamer_spec.rb](spec/streamer_spec.rb)).
134
154
 
135
155
  ## Feedback
@@ -5,8 +5,9 @@ module Json
5
5
  class JsonStreamer
6
6
 
7
7
  attr_reader :aggregator
8
+ attr_reader :parser
8
9
 
9
- def initialize(file_io, chunk_size = 1000)
10
+ def initialize(file_io = nil, chunk_size = 1000)
10
11
  @parser = JSON::Stream::Parser.new
11
12
 
12
13
  @file_io = file_io
@@ -64,8 +65,10 @@ module Json
64
65
  @current_nesting_level -= 1
65
66
  end
66
67
 
67
- @file_io.each(@chunk_size) do |chunk|
68
- @parser << chunk
68
+ if @file_io
69
+ @file_io.each(@chunk_size) do |chunk|
70
+ @parser << chunk
71
+ end
69
72
  end
70
73
  end
71
74
 
@@ -1,5 +1,5 @@
1
1
  module Json
2
2
  module Streamer
3
- VERSION = "1.0.0"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-streamer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thisismydesign
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-24 00:00:00.000000000 Z
11
+ date: 2017-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler