Class: ROM::CouchDB::Dataset

Inherits:
Object
  • Object
show all
Extended by:
Initializer
Includes:
DataProxy
Defined in:
lib/rom/couchdb/dataset.rb

Overview

CouchDB Dataset

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, options = {}) ⇒ Dataset

Returns a new instance of Dataset.



18
19
20
21
# File 'lib/rom/couchdb/dataset.rb', line 18

def initialize(data, options = {})
  @data = data
  super
end

Instance Attribute Details

#resultsObject (readonly)

Returns the value of attribute results.



13
14
15
# File 'lib/rom/couchdb/dataset.rb', line 13

def results
  @results
end

Class Method Details

.row_procObject



61
62
63
# File 'lib/rom/couchdb/dataset.rb', line 61

def self.row_proc
  TransprocFunctions[:symbolize_keys]
end

Instance Method Details

#countObject



39
40
41
# File 'lib/rom/couchdb/dataset.rb', line 39

def count
  @data.count
end

#delete(object) ⇒ Object



33
34
35
36
37
# File 'lib/rom/couchdb/dataset.rb', line 33

def delete(object)
  input = stringify_proc.call(object.dup)
  @connection.delete_doc(input)
  self
end

#find_by_id(id, params = {}) ⇒ Object



47
48
49
50
# File 'lib/rom/couchdb/dataset.rb', line 47

def find_by_id(id, params = {})
  document = @connection.get(id, params).to_hash
  self.class.new([document], connection: @connection)
end

#find_by_view(name, params = {}) ⇒ Object



52
53
54
55
# File 'lib/rom/couchdb/dataset.rb', line 52

def find_by_view(name, params = {})
  results = @connection.view(name, params)
  self.class.new([results], connection: @connection)
end

#insert(object) ⇒ Object Also known as: <<



23
24
25
26
27
28
29
30
# File 'lib/rom/couchdb/dataset.rb', line 23

def insert(object)
  input = stringify_proc.call(object.dup)
  resp = @connection.save_doc(input)
  # send back the id and revision of the document
  object[:_id] = resp['id']
  object[:_rev] = resp['rev']
  self
end

#stringify_procObject



57
58
59
# File 'lib/rom/couchdb/dataset.rb', line 57

def stringify_proc
  TransprocFunctions[:stringify_keys]
end

#to_aObject



43
44
45
# File 'lib/rom/couchdb/dataset.rb', line 43

def to_a
  @data
end