summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/tapicero/user_database.rb11
-rw-r--r--lib/tapicero/user_event_handler.rb21
2 files changed, 19 insertions, 13 deletions
diff --git a/lib/tapicero/user_database.rb b/lib/tapicero/user_database.rb
index d35af20..6daccf3 100644
--- a/lib/tapicero/user_database.rb
+++ b/lib/tapicero/user_database.rb
@@ -8,13 +8,6 @@ module Tapicero
@db = couch.database(config.options[:db_prefix] + user_id)
end
- def prepare
- create
- secure
- add_design_docs
- Tapicero.logger.info "Prepared storage " + db.name
- end
-
def create
retry_request_once "Creating database" do
create_db
@@ -53,6 +46,10 @@ module Tapicero
end
end
+ def name
+ db.name
+ end
+
protected
def create_db
diff --git a/lib/tapicero/user_event_handler.rb b/lib/tapicero/user_event_handler.rb
index 337cc06..d19e23d 100644
--- a/lib/tapicero/user_event_handler.rb
+++ b/lib/tapicero/user_event_handler.rb
@@ -3,8 +3,7 @@ module Tapicero
class UserEventHandler
def initialize(users)
users.created do |hash|
- logger.debug "Created user " + hash['id']
- user_database(hash['id']).prepare
+ prepare_db(hash['id'])
end
# Sometimes changes log starts with rev 2. So the
@@ -12,16 +11,26 @@ module Tapicero
# 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
+ prepare_db(hash['id'])
end
users.deleted do |hash|
- logger.debug "Deleted user " + hash['id']
- user_database(hash['id']).destroy
+ destroy_db(hash['id'])
end
end
+ 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