From 7958827a0ba1126646e01314e7c6bb4f86292dc8 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 10 Sep 2013 18:57:52 +0200 Subject: use our own JsonStream and a created callback in CouchChanges --- lib/tapicero/couch_changes.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'lib/tapicero/couch_changes.rb') diff --git a/lib/tapicero/couch_changes.rb b/lib/tapicero/couch_changes.rb index 2e668dc..abb451d 100644 --- a/lib/tapicero/couch_changes.rb +++ b/lib/tapicero/couch_changes.rb @@ -4,16 +4,32 @@ module Tapicero @stream = stream end + def created(hash = {}, &block) + if block_given? + @created = block + else + @created && @created.call(hash) + end + end + def last_seq @stream.get "_changes", :limit => 1, :descending => true do |hash| return hash[:last_seq] end end - def follow + def listen @stream.get "_changes", :feed => :continuous, :since => last_seq do |hash| - yield(hash) + callbacks(hash) end end + + def callbacks(hash) + #changed + return if hash[:deleted] + return unless changes = hash[:changes] + return created(hash) if changes[0][:rev].start_with?('1-') + #updated + end end end -- cgit v1.2.3