diff options
author | jessib <jessib@riseup.net> | 2014-02-04 10:42:52 -0800 |
---|---|---|
committer | jessib <jessib@riseup.net> | 2014-02-04 10:42:52 -0800 |
commit | 5b8034411f0394f90ff78f48d02db2bf8ef3e33d (patch) | |
tree | 3358f5e73b2d0dcdfe7ceb0b86ea7bb89e4dde85 /lib/tapicero/user_event_handler.rb | |
parent | c7f376cdc02fe10c7e2a51c7d52475ab34451577 (diff) | |
parent | 7bb4ab417c0275fcca03abe338b3b81c17b17a6e (diff) |
Merge pull request #10 from azul/refactor/user-database
Refactor/user database
Diffstat (limited to 'lib/tapicero/user_event_handler.rb')
-rw-r--r-- | lib/tapicero/user_event_handler.rb | 44 |
1 files changed, 44 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..38cf8f8 --- /dev/null +++ b/lib/tapicero/user_event_handler.rb @@ -0,0 +1,44 @@ +require 'tapicero/user_database' +module Tapicero + class UserEventHandler + def initialize(users) + users.created do |hash| + prepare_db(hash['id']) + 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| + prepare_db(hash['id']) + end + + users.deleted do |hash| + destroy_db(hash['id']) + end + end + + protected + + def prepare_db(id) + db = user_database(id) + db.create + db.secure + db.add_design_docs + logger.info "Prepared storage " + db.name + end + + def destroy_db(id) + user_database(id).destroy + end + + def logger + Tapicero.logger + end + + def user_database(id) + UserDatabase.new(id) + end + end +end |