json-streamer 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +24 -4
- data/lib/json/streamer/json_streamer.rb +6 -3
- data/lib/json/streamer/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: defb27980ce9856c197b03d9dcd036c6a9676faf
         | 
| 4 | 
            +
              data.tar.gz: be55ab586714595baab1ae9e570fc5c0d1c869d9
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: ccefc6735d211f77a1cd1c18b05073d0d585033478f8495a922402dbf8c479b9f9eb3804a53c55c6f5b21b6dc8c93873ab9a569df97e95daefd5d04e24a9432d
         | 
| 7 | 
            +
              data.tar.gz: c132b1c90100166e7716959b12fa085e64ebfaa754fcfc919e20c290537704d1e915632846ae680b697fe3a29adefafdd751e1cc79ae6685b510da6c9d6801a2
         | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -1,12 +1,12 @@ | |
| 1 1 | 
             
            # Json::Streamer
         | 
| 2 2 |  | 
| 3 | 
            -
             | 
| 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 | [](https://travis-ci.org/thisismydesign/json-streamer)   [](https://coveralls.io/github/thisismydesign/json-streamer?branch=release)   [](https://badge.fury.io/rb/json-streamer) |
         | 
| 6 8 | 
             
            | Development | [](https://travis-ci.org/thisismydesign/json-streamer)   [](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 | 
| 68 | 
            -
                      @ | 
| 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 |  | 
    
        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. | 
| 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- | 
| 11 | 
            +
            date: 2017-05-29 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         |