Sha256: df3849440b5c6dc17a853951ed16c68c55ed461b77dfa20d19b11a76900aed1d

Contents?: true

Size: 835 Bytes

Versions: 1

Compression:

Stored size: 835 Bytes

Contents

require 'riak/util/escape'
require 'riak/json'

module Riak
   class Client
     class HTTPBackend
       # @private
       class KeyStreamer
         include Util::Escape

         def initialize(block)
           @buffer = ""
           @block = block
         end

         def accept(chunk)
           @buffer << chunk
           consume
         end

         def to_proc
           method(:accept).to_proc
         end

         private
         def consume
           while @buffer =~ /\}\{/
             stream($~.pre_match + '}')
             @buffer = '{' + $~.post_match
           end
         end

         def stream(str)
           obj = JSON.parse(str) rescue nil
           if obj && obj['keys']
             @block.call obj['keys'].map(&method(:unescape))
           end
         end
       end
     end
   end
 end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
seomoz-riak-client-1.0.0.pre lib/riak/client/http_backend/key_streamer.rb