Class: Kvom::Adapter::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/kvom/adapter/base.rb

Direct Known Subclasses

DynamodbAdapter, FilesystemAdapter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection_spec_raw) ⇒ Base

Returns a new instance of Base.



11
12
13
14
# File 'lib/kvom/adapter/base.rb', line 11

def initialize(connection_spec_raw)
  @connection_spec = connection_spec_raw.symbolize_keys
  @documents_loaded_counter = @request_counter = 0
end

Instance Attribute Details

#connection_specObject (readonly)

Returns the value of attribute connection_spec.



7
8
9
# File 'lib/kvom/adapter/base.rb', line 7

def connection_spec
  @connection_spec
end

#documents_loaded_counterObject (readonly)

Returns the value of attribute documents_loaded_counter.



9
10
11
# File 'lib/kvom/adapter/base.rb', line 9

def documents_loaded_counter
  @documents_loaded_counter
end

#request_counterObject (readonly)

Returns the value of attribute request_counter.



9
10
11
# File 'lib/kvom/adapter/base.rb', line 9

def request_counter
  @request_counter
end

Instance Method Details

#destroy(doc) ⇒ Object



40
41
42
43
44
45
# File 'lib/kvom/adapter/base.rb', line 40

def destroy(doc)
  count_request do
    key = doc.key
    destroy_doc(doc)
  end
end

#destroy_index(key) ⇒ Object



47
48
49
50
51
# File 'lib/kvom/adapter/base.rb', line 47

def destroy_index(key)
  count_request do
    destroy_index_doc(key)
  end
end

#get(key) ⇒ Object



20
21
22
23
24
# File 'lib/kvom/adapter/base.rb', line 20

def get(key)
  count_document_request do
    read_doc(key)
  end
end

#new_document(key, attributes) ⇒ Object



16
17
18
# File 'lib/kvom/adapter/base.rb', line 16

def new_document(key, attributes)
  raise "implement me in subclass!"
end

#query(hash_value, range_value, query_options = {}) ⇒ Object



53
54
55
56
57
58
# File 'lib/kvom/adapter/base.rb', line 53

def query(hash_value, range_value, query_options={})
  query_options.assert_valid_keys(:limit, :scan_index_forward)
  count_document_request do
    query_docs(hash_value, range_value, query_options)
  end
end

#range_values_of_hash_value(hash_value) ⇒ Object



60
61
62
63
64
# File 'lib/kvom/adapter/base.rb', line 60

def range_values_of_hash_value(hash_value)
  count_request do
    doc_range_values_of_hash_value(hash_value)
  end
end

#save(doc) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/kvom/adapter/base.rb', line 26

def save(doc)
  doc.update_revision do
    count_request do
      write_doc(doc)
    end
  end
end

#save_index(key) ⇒ Object



34
35
36
37
38
# File 'lib/kvom/adapter/base.rb', line 34

def save_index(key)
  count_request do
    write_index_doc(key)
  end
end