diff options
author | Azul <azul@riseup.net> | 2014-02-04 14:14:54 +0100 |
---|---|---|
committer | Azul <azul@riseup.net> | 2014-02-04 14:14:54 +0100 |
commit | ecf7188143d09c091f89b1970269e04fc7cba4e8 (patch) | |
tree | b2db3a9fe4a35efe4935fa626f71d55219c6e045 /lib/tapicero | |
parent | a8194a21cb9f452adb77d24b60434f921c60d496 (diff) |
refactor: separate user event handler
Diffstat (limited to 'lib/tapicero')
-rw-r--r-- | lib/tapicero/user_event_handler.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/tapicero/user_event_handler.rb b/lib/tapicero/user_event_handler.rb new file mode 100644 index 0000000..337cc06 --- /dev/null +++ b/lib/tapicero/user_event_handler.rb @@ -0,0 +1,33 @@ +require 'tapicero/user_database' +module Tapicero + class UserEventHandler + def initialize(users) + users.created do |hash| + logger.debug "Created user " + hash['id'] + user_database(hash['id']).prepare + 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 + end + + users.deleted do |hash| + logger.debug "Deleted user " + hash['id'] + user_database(hash['id']).destroy + end + end + + def logger + Tapicero.logger + end + + def user_database(id) + UserDatabase.new(id) + end + end +end |