Class: Aqua::Store::CouchDB::ResultSet

Inherits:
Array
  • Object
show all
Defined in:
lib/aqua/store/couch_db/result_set.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Array

aqua_init, #to_aqua_init

Constructor Details

#initialize(response, doc_class = nil) ⇒ ResultSet

Returns a new instance of ResultSet.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/aqua/store/couch_db/result_set.rb', line 16

def initialize( response, doc_class=nil )
  self.document_class = doc_class || self.class.document_class
  self.total    = response['total_rows']
  self.offset   = response['offset']
  self.rows     = response['rows']
  results = if rows && rows.first && rows.first['doc']
    if document_class
      rows.collect{ |h| document_class.new( h['doc'] ) }
    else
      rows.collect{ |h| h['doc'] }
    end    
  else
    rows.collect{ |h| h['key'] } 
  end    
  super( results )
end

Instance Attribute Details

#document_classObject

Returns the value of attribute document_class.



14
15
16
# File 'lib/aqua/store/couch_db/result_set.rb', line 14

def document_class
  @document_class
end

#offsetObject

Returns the value of attribute offset.



14
15
16
# File 'lib/aqua/store/couch_db/result_set.rb', line 14

def offset
  @offset
end

#rowsObject

Returns the value of attribute rows.



14
15
16
# File 'lib/aqua/store/couch_db/result_set.rb', line 14

def rows
  @rows
end

#totalObject

Returns the value of attribute total.



14
15
16
# File 'lib/aqua/store/couch_db/result_set.rb', line 14

def total
  @total
end

Class Method Details

.document_classObject



6
7
8
# File 'lib/aqua/store/couch_db/result_set.rb', line 6

def self.document_class
  @document_class
end

.document_class=(klass) ⇒ Object



10
11
12
# File 'lib/aqua/store/couch_db/result_set.rb', line 10

def self.document_class=( klass )
  @document_class = klass
end