Class: Couchy::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/couchy/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Server

Returns a new instance of Server.



5
6
7
# File 'lib/couchy/server.rb', line 5

def initialize(uri)
  @uri = Addressable::URI.parse(uri)
end

Instance Attribute Details

#uriObject

Returns the value of attribute uri.



3
4
5
# File 'lib/couchy/server.rb', line 3

def uri
  @uri
end

Instance Method Details

#create_db(name) ⇒ Couchy::Database

Creates a database

Parameters:

  • name (String)

    Database’s name

Returns:



44
45
46
47
# File 'lib/couchy/server.rb', line 44

def create_db(name)
  put(name)
  database(name)
end

#database(name) ⇒ Couchy::Database

Gets a new [Couchy::Database] for the database

Parameters:

  • name (String)

    The name of the database

Returns:



35
36
37
# File 'lib/couchy/server.rb', line 35

def database(name)
  Database.new(self, name)
end

#databasesArray

Gets a list of all the databases available on the server

Returns:

  • (Array)

    Parsed server response



26
27
28
# File 'lib/couchy/server.rb', line 26

def databases
  get '_all_dbs'
end

#delete(path, params = {}) ⇒ Object



66
67
68
# File 'lib/couchy/server.rb', line 66

def delete(path, params={})
  json RestClient.delete(uri_for(path, params))
end

#get(path, params = {}) ⇒ Object



49
50
51
52
53
# File 'lib/couchy/server.rb', line 49

def get(path, params={})
  need_json = !params.delete(:no_json)
  response = RestClient.get(uri_for(path, params))
  need_json ? json(response, :max_nesting => false) : response
end

#infoHash

Gets information about the server

Returns:

  • (Hash)

    Parsed server response



12
13
14
# File 'lib/couchy/server.rb', line 12

def info
  get '/'
end

#post(path, doc = nil, params = {}) ⇒ Object



55
56
57
58
59
# File 'lib/couchy/server.rb', line 55

def post(path, doc=nil, params={})
  headers = params.delete(:headers)
  payload = doc.to_json if doc
  json RestClient.post(uri_for(path, params), payload, headers)
end

#put(path, doc = nil) ⇒ Object



61
62
63
64
# File 'lib/couchy/server.rb', line 61

def put(path, doc=nil)
  payload = doc.to_json if doc
  json RestClient.put(uri_for(path), payload)
end

#restart!Hash

Restarts the server

Returns:

  • (Hash)

    Parsed server response



19
20
21
# File 'lib/couchy/server.rb', line 19

def restart!
  post '_restart'
end