summaryrefslogtreecommitdiff
path: root/lib/tapicero/user_database.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tapicero/user_database.rb')
-rw-r--r--lib/tapicero/user_database.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/tapicero/user_database.rb b/lib/tapicero/user_database.rb
new file mode 100644
index 0000000..fcdd272
--- /dev/null
+++ b/lib/tapicero/user_database.rb
@@ -0,0 +1,39 @@
+require 'couchrest'
+require 'json'
+
+module Tapicero
+ class UserDatabase
+
+ def initialize(host, name)
+ @host = host
+ @name = name
+ end
+
+ def create
+ begin
+ CouchRest.new(host).create_db(name)
+ rescue RestClient::PreconditionFailed # database already existed
+ end
+ end
+
+ def secure(security)
+ # let's not overwrite if we have a security doc already
+ return if secured?
+ puts security.to_json
+ puts "-> #{security_url}"
+ CouchRest.put security_url, security
+ end
+
+ protected
+
+ def secured?
+ CouchRest.get(security_url).keys.any?
+ end
+
+ def security_url
+ "#{host}/#{name}/_security"
+ end
+
+ attr_reader :host, :name
+ end
+end