Skip to content

Instantly share code, notes, and snippets.

@mulder
Created September 26, 2011 19:39
Show Gist options
  • Save mulder/1243188 to your computer and use it in GitHub Desktop.
Save mulder/1243188 to your computer and use it in GitHub Desktop.
class Streamer
def initialize(records, &block)
@block = nil
@records = records
@record_block = block
end
def write(bytes)
@block.call bytes
bytes.bytesize
end
def each(&block)
@block = block
stream = Psych::JSON::Stream.new self
@records.each do |record|
stream << @record_block.call(record)
end
end
end
def events
do_not_cache
self.response_body = Streamer.new(subscribed_events) do |event|
event.to_json
end
end
@mulder
Copy link
Author

mulder commented Sep 26, 2011

gem 'psych'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment