diff options
author | Matthias Hecker <apoc@geekosphere.org> | 2015-06-14 19:31:55 +0200 |
---|---|---|
committer | Matthias Hecker <apoc@geekosphere.org> | 2015-06-14 19:31:55 +0200 |
commit | 075c7e031b3449ff026e51a2299f56df573ef688 (patch) | |
tree | 2631d2aa23352c9642cb11baf35100b367b1e378 /lib/rbot/journal.rb | |
parent | 65de5ebca22a2d17729a63589240c734b5ca4de1 (diff) |
journal: more postgres tests
Diffstat (limited to 'lib/rbot/journal.rb')
-rw-r--r-- | lib/rbot/journal.rb | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/lib/rbot/journal.rb b/lib/rbot/journal.rb index cc0578de..71b0c7ff 100644 --- a/lib/rbot/journal.rb +++ b/lib/rbot/journal.rb @@ -76,7 +76,7 @@ module Journal end def ==(other) - @id == other.id + (@id == other.id) rescue false end def self.create(topic, payload, opt={}) @@ -104,16 +104,32 @@ module Journal end # returns a array of message instances that match the query - def find(query, limit=10, offset=0) + def find(query=nil, limit=100, offset=0) end # returns the number of messages that match the query - def count(query) + def count(query=nil) end - # delete messages that match the query - def delete(query) + # remove messages that match the query + def remove(query=nil) end + + # destroy the underlying table/collection + def drop + end + + # Returns all classes from the namespace that implement this interface + def self.get_impl + ObjectSpace.each_object(Class).select { |klass| klass < self } + end + end + + def create(name, uri) + log 'load journal storage adapter: ' + name + load File.join(File.dirname(__FILE__), 'journal', name + '.rb') + cls = AbstractStorage.get_impl.first + cls.new(uri: uri) end end @@ -270,7 +286,12 @@ module Journal # overrides the internal consumer with a block @consumer = opts[:consumer] # storage backend - @storage = opts[:storage] + if @bot + @storage = opts[:storage] || Storage.create( + @bot.config['journal.storage'], @bot.config['journal.storage.uri']) + else + @storage = opts[:storage] + end @queue = Queue.new # consumer thread: @thread = Thread.new do @@ -334,6 +355,17 @@ module Journal @subscriptions.delete subscription end + def find(query, limit=100, offset=0, &block) + if block_given? + begin + res = @storage.find(query, limit, offset) + block.call(res) + end until res.length > 0 + else + @storage.find(query, limit, offset) + end + end + end end # Journal |