diff options
Diffstat (limited to 'lib/tapicero/user_database.rb')
-rw-r--r-- | lib/tapicero/user_database.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/tapicero/user_database.rb b/lib/tapicero/user_database.rb index 8f461ef..efd723a 100644 --- a/lib/tapicero/user_database.rb +++ b/lib/tapicero/user_database.rb @@ -23,6 +23,22 @@ module Tapicero CouchRest.put security_url, security end + def add_design_docs + pattern = BASE_DIR + 'designs' + '*.json' + Tapicero.logger.debug "looking for design docs in #{pattern}" + Pathname.glob(pattern).each do |file| + upload_design_doc(file) + end + end + + def upload_design_doc(file) + url = design_url(file.basename('.json')) + CouchRest.put url, JSON.parse(file.read) + Tapicero.logger.debug "uploaded design doc #{file.basename} to #{url}" + rescue RestClient::Conflict + end + + def destroy db = CouchRest.new(host).database(name) db.delete! if db @@ -40,6 +56,10 @@ module Tapicero "#{host}/#{name}/_security" end + def design_url(doc_name) + "#{host}/#{name}/_design/#{doc_name}" + end + attr_reader :host, :name end end |