summaryrefslogtreecommitdiff
path: root/lib/tapicero/couch_changes.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tapicero/couch_changes.rb')
-rw-r--r--lib/tapicero/couch_changes.rb20
1 files changed, 18 insertions, 2 deletions
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