Module: Sovaa

Defined in:
lib/sovaa.rb,
lib/sovaa/http.rb,
lib/sovaa/server.rb,
lib/sovaa/database.rb,
lib/sovaa/json_response.rb

Overview

CouchDB, close to the metal

Defined Under Namespace

Modules: HTTP Classes: Conflict, Database, HTTPError, Invalid, JsonResponse, NotFound, Server

Constant Summary collapse

VERSION =
'1.0.1'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.proxyObject

Returns the value of attribute proxy.



69
70
71
# File 'lib/sovaa.rb', line 69

def proxy
  @proxy
end

Class Method Details

.database(url) ⇒ Object



80
81
82
83
84
# File 'lib/sovaa.rb', line 80

def database url
  parsed = parse url
  cr = Sovaa.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



74
75
76
77
78
# File 'lib/sovaa.rb', line 74

def database! url
  parsed = parse url
  cr = Sovaa.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.



31
32
33
# File 'lib/sovaa.rb', line 31

def new(*opts)
  Server.new(*opts)
end

.paramify_url(url, params = {}) ⇒ Object



86
87
88
89
90
91
92
93
94
95
# File 'lib/sovaa.rb', line 86

def paramify_url url, params = {}
  if params && !params.empty?
    query = params.collect do |k,v|
      v = Yajl::Encoder.encode(v) 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



35
36
37
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
# File 'lib/sovaa.rb', line 35

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