mingle_keyvalue_store 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mingle_keyvalue_store.rb +36 -29
  3. metadata +9 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49d84696711f09b6af8abf2d0d2dcab9ad900c23
4
- data.tar.gz: fdec133312a875c06258190471b1ff3491ed7f9b
3
+ metadata.gz: c7593599a6ad46df392ee8566d74469423eac688
4
+ data.tar.gz: 519761c18f684b06b47592fe8a825c9b29231c59
5
5
  SHA512:
6
- metadata.gz: bcaef1f60faad66156ba24e4fe41aef9562ee7e0786816f4358ec88f1fdde2a43040c7be79641193fcf2d33a2d7d3d22b39edd9eaeab8e179521ab906dfaaea7
7
- data.tar.gz: 567f4ca17836fa2fb96e9087d6b48da9913f0e35d80e098c10b898e8ca61244f2aef42d1d961e43552c11ae6facfa4e4d8307ab2df23c08645e1bb71451b1bb1
6
+ metadata.gz: 012643285c3c887c6db00c0cf1630604adc884b87c08bdc76af06914d21f03320672ce69bcee794944a4b86d916d1fa69baea1777f72e84bfcb2bdff0e451ddb
7
+ data.tar.gz: 238bd2cd4125cb5c75e42610b89ffc0f4cd00bb2165d93c72cea3abbcd262536f71e3f8963ae3bf02279568ae8fe08398f50b9dd98fe9e71953c7ddd2f3653aa
@@ -1,8 +1,7 @@
1
- require "rubygems"
2
- require "aws"
3
- require "pstore"
4
- require "fileutils"
5
- require "tempfile"
1
+ require 'aws-sdk-dynamodb'
2
+ require 'pstore'
3
+ require 'fileutils'
4
+ require 'tempfile'
6
5
  require 'monitor'
7
6
 
8
7
  module Mingle
@@ -24,11 +23,11 @@ module Mingle
24
23
  end
25
24
 
26
25
  def []=(store_key, value)
27
- raise ArgumentError, "Value must be String" unless value.is_a?(String)
26
+ raise ArgumentError, 'Value must be String' unless value.is_a?(String)
28
27
  synchronize do
29
28
  @pstore.transaction do
30
- @pstore["all_names"] ||= []
31
- @pstore["all_names"] = (@pstore["all_names"] + [store_key]).uniq
29
+ @pstore['all_names'] ||= []
30
+ @pstore['all_names'] = (@pstore['all_names'] + [store_key]).uniq
32
31
  @pstore[store_key] = value
33
32
  end
34
33
  end
@@ -37,7 +36,7 @@ module Mingle
37
36
  def delete(store_key)
38
37
  synchronize do
39
38
  @pstore.transaction do
40
- @pstore["all_names"].delete_if {|name| name == store_key}
39
+ @pstore['all_names'].delete_if {|name| name == store_key}
41
40
  @pstore.delete(store_key)
42
41
  end
43
42
  end
@@ -52,15 +51,15 @@ module Mingle
52
51
 
53
52
  def names
54
53
  synchronize do
55
- @pstore.transaction { @pstore["all_names"] || [] }
54
+ @pstore.transaction { @pstore['all_names'] || [] }
56
55
  end
57
56
  end
58
57
 
59
58
  def all_items
60
59
  synchronize do
61
60
  @pstore.transaction do
62
- return [] unless @pstore["all_names"]
63
- @pstore["all_names"].map do |name|
61
+ return [] unless @pstore['all_names']
62
+ @pstore['all_names'].map do |name|
64
63
  {
65
64
  @key_column.to_s => name,
66
65
  @value_column.to_s => @pstore[name]
@@ -80,48 +79,56 @@ module Mingle
80
79
 
81
80
  class DynamodbBased
82
81
  def initialize(table_name, key_column, value_column)
83
- @key_column = key_column
82
+ @key_column = key_column.to_s
84
83
  @value_column = value_column.to_s
85
84
  @table_name = table_name
85
+ @table = Aws::DynamoDB::Resource.new.table(table_name)
86
86
  end
87
87
 
88
88
  def [](store_key)
89
- if attribute = attributes(table_items[store_key])[@value_column]
90
- attribute
89
+ if item = @table.get_item(key: {@key_column => store_key}).item
90
+ item[@value_column]
91
91
  end
92
92
  end
93
93
 
94
94
  def []=(store_key, value)
95
- table_items.create(@key_column => store_key, @value_column => value)
95
+ raise ArgumentError, 'Value must be String' unless value.is_a?(String)
96
+ @table.put_item(item: {@key_column => store_key, @value_column => value})
96
97
  end
97
98
 
98
99
  def clear
99
- table_items.each(&:delete)
100
+ all_items_from_table.each do |item|
101
+ @table.delete_item(key: {@key_column => item['testkey']})
102
+ end
103
+ nil
100
104
  end
101
105
 
102
106
  def names
103
- table_items.map(&:hash_value)
107
+ all_items_from_table(attributes_to_get: [@key_column]).map{|hash| hash[@key_column]}
104
108
  end
105
109
 
106
110
  def all_items
107
- table_items.map { |item| attributes(item) }
111
+ all_items_from_table
108
112
  end
109
113
 
110
114
  def delete(key)
111
- table_items.where(@key_column => key).first.delete
115
+ @table.delete_item(key: {@key_column => key})
116
+ nil
112
117
  end
113
118
 
114
119
  private
115
- def attributes(item)
116
- item.attributes.to_h(:consistent_read => true)
117
- end
118
-
119
- def table_items
120
- table = AWS::DynamoDB.new.tables[@table_name]
121
- table.hash_key = [@key_column, :string]
122
- table.items
120
+ def all_items_from_table(conditions={})
121
+ items = []
122
+ scan_output = @table.scan(conditions)
123
+ return items unless scan_output.items
124
+ items += scan_output.items
125
+ # when the table data is too large scan will return in batches
126
+ while scan_output.last_evaluated_key
127
+ scan_output = @table.scan(conditions.merge(exclusive_start_key: scan_output.last_evaluated_key))
128
+ items += scan_output.items
129
+ end
130
+ items
123
131
  end
124
-
125
132
  end
126
133
  end
127
134
  end
metadata CHANGED
@@ -1,36 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mingle_keyvalue_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian
8
8
  - sdqali
9
+ - prateekbaheti
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2016-01-27 00:00:00.000000000 Z
13
+ date: 2017-09-20 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
18
  - - ~>
18
19
  - !ruby/object:Gem::Version
19
- version: '1.11'
20
- - - '>='
21
- - !ruby/object:Gem::Version
22
- version: 1.11.3
23
- name: aws-sdk
20
+ version: '1'
21
+ name: aws-sdk-dynamodb
24
22
  prerelease: false
25
23
  type: :runtime
26
24
  version_requirements: !ruby/object:Gem::Requirement
27
25
  requirements:
28
26
  - - ~>
29
27
  - !ruby/object:Gem::Version
30
- version: '1.11'
31
- - - '>='
32
- - !ruby/object:Gem::Version
33
- version: 1.11.3
28
+ version: '1'
34
29
  - !ruby/object:Gem::Dependency
35
30
  requirement: !ruby/object:Gem::Requirement
36
31
  requirements:
@@ -45,10 +40,11 @@ dependencies:
45
40
  - - '>='
46
41
  - !ruby/object:Gem::Version
47
42
  version: '0'
48
- description: A key value store implentation that uses DynamoDB or Pstore underneath.
43
+ description: A key value store implementation that uses DynamoDB or Pstore underneath.
49
44
  email:
50
45
  - reginaldthedog@gmail.com
51
46
  - sadiqalikm@gmail.com
47
+ - prateektheone@gmail.com
52
48
  executables: []
53
49
  extensions: []
54
50
  extra_rdoc_files: []
@@ -78,5 +74,5 @@ rubyforge_project:
78
74
  rubygems_version: 2.1.9
79
75
  signing_key:
80
76
  specification_version: 4
81
- summary: A key value store implentation that uses DynamoDB or Pstore underneath.
77
+ summary: A key value store implementation that uses DynamoDB or Pstore underneath.
82
78
  test_files: []