summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2013-12-19 15:59:55 +0100
committerAzul <azul@riseup.net>2013-12-19 15:59:55 +0100
commitf47712d803811f06b4371f50fabdfc1fefffe4cc (patch)
treec079d8802695c21fececba629e4446b23044145d
parente4df501035434cbb1920ccca21e489599b5ad382 (diff)
add design docs on db creation, use Pathname
Pathname makes dealing with files easier than String. Tapicero will look for design documents in design directory in the tapicero path for now.
-rwxr-xr-xbin/tapicero5
-rw-r--r--lib/tapicero.rb2
-rw-r--r--lib/tapicero/user_database.rb19
-rw-r--r--lib/tapicero_daemon.rb1
4 files changed, 24 insertions, 3 deletions
diff --git a/bin/tapicero b/bin/tapicero
index 9a5a7ee..b8b88f1 100755
--- a/bin/tapicero
+++ b/bin/tapicero
@@ -1,10 +1,11 @@
#!/usr/bin/ruby
+require 'pathname'
#
# Tapicero Daemon
#
-BASE_DIR = File.expand_path('../..', File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__)
+BASE_DIR = Pathname.new(__FILE__).realpath + '../..'
begin
#
@@ -17,7 +18,7 @@ rescue LoadError
#
require "#{BASE_DIR}/lib/tapicero/version.rb"
Tapicero::REQUIRE_PATHS.each do |path|
- path = File.expand_path(path, BASE_DIR)
+ path = BASE_DIR + path
$LOAD_PATH.unshift path unless $LOAD_PATH.include?(path)
end
require 'rubygems'
diff --git a/lib/tapicero.rb b/lib/tapicero.rb
index aba9fad..3923c65 100644
--- a/lib/tapicero.rb
+++ b/lib/tapicero.rb
@@ -1,5 +1,5 @@
unless defined? BASE_DIR
- BASE_DIR = File.expand_path('../..', __FILE__)
+ BASE_DIR = Pathname.new(__FILE__) + '../..'
end
unless defined? TAPICERO_CONFIG
TAPICERO_CONFIG = '/etc/leap/tapicero.yaml'
diff --git a/lib/tapicero/user_database.rb b/lib/tapicero/user_database.rb
index 8f461ef..b08558f 100644
--- a/lib/tapicero/user_database.rb
+++ b/lib/tapicero/user_database.rb
@@ -23,6 +23,21 @@ 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)
+ Tapicero.logger.debug "uploading design doc #{file.basename} to #{url}"
+ CouchRest.put url, JSON.parse(file.read)
+ end
+
+
def destroy
db = CouchRest.new(host).database(name)
db.delete! if db
@@ -40,6 +55,10 @@ module Tapicero
"#{host}/#{name}/_security"
end
+ def design_url(doc_name)
+ "#{host}/#{name}/_design/#{doc_name}"
+ end
+
attr_reader :host, :name
end
end
diff --git a/lib/tapicero_daemon.rb b/lib/tapicero_daemon.rb
index 9020fa2..67eee88 100644
--- a/lib/tapicero_daemon.rb
+++ b/lib/tapicero_daemon.rb
@@ -15,6 +15,7 @@ module Tapicero
db = user_database(hash['id'])
db.create
db.secure(config.options[:security])
+ db.add_design_docs
end
users.deleted do |hash|