summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2014-02-04 15:01:27 +0100
committerAzul <azul@riseup.net>2014-02-04 15:01:27 +0100
commit5cd3df1a9be8e7db2f3e364fd730ed78c8d0e49f (patch)
tree1bdb67cf7e501655e8503fbb4fc0e81a7df3d96f
parentecf7188143d09c091f89b1970269e04fc7cba4e8 (diff)
refactor: moved prepare and destroy into user_event_handler
-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