summaryrefslogtreecommitdiff
path: root/lib/tapicero_daemon.rb
blob: 23248e3e140159b308c0d64eefe9e92434439b63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#
# This file should not be required directly. Use the wrapper in /bin
# instead or run this using daemons:
#
#  Daemons.run('tapicero_daemon.rb')
#

require 'tapicero'

module Tapicero
  users = CouchRest::Changes.new('users')

  users.created do |hash|
    logger.debug "Created user " + hash['id']
    user_database(hash['id']).prepare(config)
  end

  # Sometimes changes log starts with rev 2. So the
  # detection of is currently not working properly
  # Working around this until a new version of
  # couchrest changes takes this into account.
  users.updated do |hash|
    logger.debug "Updated user " + hash['id']
    user_database(hash['id']).prepare(config)
  end

  users.deleted do |hash|
    logger.debug "Deleted user " + hash['id']
    user_database(hash['id']).destroy
  end

  users.listen
end