Module: CouchRest

Defined in:
lib/couchrest.rb,
lib/couchrest/core/server.rb,
lib/couchrest/helper/pager.rb,
lib/couchrest/commands/push.rb,
lib/couchrest/core/database.rb,
lib/couchrest/helper/streamer.rb,
lib/couchrest/commands/generate.rb,
lib/couchrest/helper/file_manager.rb

Defined Under Namespace

Modules: Commands Classes: Database, FileManager, Pager, Server, Streamer

Class Method Summary collapse

Class Method Details

.database(url) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/couchrest.rb', line 55

def database url
  uri = URI.parse url
  path = uri.path
  uri.path = ''
  cr = CouchRest.new(uri.to_s)
  cr.database(path)
end

.database!(url) ⇒ Object

ensure that a database exists creates it if it isn’t already there returns it after it’s been created



47
48
49
50
51
52
53
# File 'lib/couchrest.rb', line 47

def database! url
  uri = URI.parse url
  path = uri.path
  uri.path = ''
  cr = CouchRest.new(uri.to_s)
  cr.database!(path)
end

.delete(uri) ⇒ Object



77
78
79
# File 'lib/couchrest.rb', line 77

def delete uri
  JSON.parse(RestClient.delete(uri))
end

.get(uri) ⇒ Object



68
69
70
# File 'lib/couchrest.rb', line 68

def get uri
  JSON.parse(RestClient.get(uri), :max_nesting => false)
end

.new(*opts) ⇒ Object

todo, make this parse the url and instantiate a Server or Database instance depending on the specificity.



40
41
42
# File 'lib/couchrest.rb', line 40

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

.paramify_url(url, params = nil) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'lib/couchrest.rb', line 81

def paramify_url url, params = nil
  if params
    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

.post(uri, doc = nil) ⇒ Object



72
73
74
75
# File 'lib/couchrest.rb', line 72

def post uri, doc = nil
  payload = doc.to_json if doc
  JSON.parse(RestClient.post(uri, payload))
end

.put(uri, doc = nil) ⇒ Object



63
64
65
66
# File 'lib/couchrest.rb', line 63

def put uri, doc = nil
  payload = doc.to_json if doc
  JSON.parse(RestClient.put(uri, payload))
end