Module: Sova
- Defined in:
- lib/sova.rb,
lib/sova/http.rb,
lib/sova/server.rb,
lib/sova/database.rb
Overview
CouchDB, close to the metal
Defined Under Namespace
Modules: HTTP Classes: Conflict, Database, HTTPError, Invalid, NotFound, Server
Constant Summary collapse
- VERSION =
'1.0.1'
Class Attribute Summary collapse
-
.proxy ⇒ Object
Returns the value of attribute proxy.
Class Method Summary collapse
- .database(url) ⇒ Object
-
.database!(url) ⇒ Object
ensure that a database exists creates it if it isn’t already there returns it after it’s been created.
-
.new(*opts) ⇒ Object
todo, make this parse the url and instantiate a Server or Database instance depending on the specificity.
- .paramify_url(url, params = {}) ⇒ Object
- .parse(url) ⇒ Object
Class Attribute Details
.proxy ⇒ Object
Returns the value of attribute proxy.
72 73 74 |
# File 'lib/sova.rb', line 72 def proxy @proxy end |
Class Method Details
.database(url) ⇒ Object
83 84 85 86 87 |
# File 'lib/sova.rb', line 83 def database url parsed = parse url cr = Sova.new(parsed[:host]) cr.database(parsed[:database]) end |
.database!(url) ⇒ Object
ensure that a database exists creates it if it isn’t already there returns it after it’s been created
77 78 79 80 81 |
# File 'lib/sova.rb', line 77 def database! url parsed = parse url cr = Sova.new(parsed[:host]) cr.database!(parsed[:database]) end |
.new(*opts) ⇒ Object
todo, make this parse the url and instantiate a Server or Database instance depending on the specificity.
34 35 36 |
# File 'lib/sova.rb', line 34 def new(*opts) Server.new(*opts) end |
.paramify_url(url, params = {}) ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/sova.rb', line 89 def paramify_url url, params = {} if params && !params.empty? query = params.collect do |k,v| v = v.to_json if %w{key startkey endkey}.include?(k.to_s) "#{k}=#{CGI.escape(v.to_s)}" end.join("&") url = "#{url}?#{query}" end url end |
.parse(url) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/sova.rb', line 38 def parse url case url when /^(https?:\/\/)(.*)\/(.*)\/(.*)/ scheme = $1 host = $2 db = $3 docid = $4 when /^(https?:\/\/)(.*)\/(.*)/ scheme = $1 host = $2 db = $3 when /^(https?:\/\/)(.*)/ scheme = $1 host = $2 when /(.*)\/(.*)\/(.*)/ host = $1 db = $2 docid = $3 when /(.*)\/(.*)/ host = $1 db = $2 else db = url end db = nil if db && db.empty? { :host => (scheme || "http://") + (host || "127.0.0.1:5984"), :database => db, :doc => docid } end |