Class: CouchDatabase

Inherits:
CouchIO show all
Includes:
Enumerable
Defined in:
lib/couchio/couch_database.rb

Instance Attribute Summary collapse

Attributes inherited from CouchIO

#append, #path, #readable, #writeable

Instance Method Summary collapse

Methods inherited from CouchIO

#close

Constructor Details

#initialize(*args, &block) ⇒ CouchDatabase

Returns a new instance of CouchDatabase.



7
8
9
10
# File 'lib/couchio/couch_database.rb', line 7

def initialize(*args, &block)
  super
  @pos = 0
end

Instance Attribute Details

#posObject Also known as: tell

Returns the value of attribute pos.



4
5
6
# File 'lib/couchio/couch_database.rb', line 4

def pos
  @pos
end

Instance Method Details

#createObject



26
27
28
29
30
31
32
33
34
# File 'lib/couchio/couch_database.rb', line 26

def create
  uri = URI.parse(path)
  Net::HTTP.start(uri.host, uri.port) do |http|
    result = http.send_request('PUT', uri.path)
    json = JSON.parse(result.body)
    verify_ok(json)
  end
  0
end

#deleteObject Also known as: unlink, rmdir



36
37
38
39
40
41
42
43
44
# File 'lib/couchio/couch_database.rb', line 36

def delete
  uri = URI.parse(path)
  Net::HTTP.start(uri.host, uri.port) do |http|
    result = http.delete(uri.path)
    json = JSON.parse(result.body)
    verify_ok(json)
  end
  0
end

#eachObject



15
16
17
# File 'lib/couchio/couch_database.rb', line 15

def each 
  rows.each {|row| yield row }
end

#readObject



19
20
21
22
23
24
# File 'lib/couchio/couch_database.rb', line 19

def read
  @rows ||= rows
  result = @rows[@pos]
  @pos += 1
  result
end

#rewindObject



12
# File 'lib/couchio/couch_database.rb', line 12

def rewind; @pos = 0; self end

#seek(n) ⇒ Object



13
# File 'lib/couchio/couch_database.rb', line 13

def seek(n) @pos = n; self end