tiny_dyno 0.1.9 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a57635fe6ebcd452a54d007997380f6616bb0f3
4
- data.tar.gz: 3e7518b99d5034175ea1781ac4f39812a722c7fa
3
+ metadata.gz: 3a5a334e766b682c0dd8efe2eb7ac34fc4cf85ce
4
+ data.tar.gz: 1e7428905fab9f8cf20ab1d30ce0dc3446badc47
5
5
  SHA512:
6
- metadata.gz: cd0dc92db501ed54364de063d527acb8ccb3a115ed27585a1c6c4c5f3e0f73ed65a9441d569150fb6c095f52b58eb0c59bcf313e21949a100cd92a6e3dada745
7
- data.tar.gz: e6d2aee6af7d226e667e0e7f522d227daf5662b1f725c961b95ce097e4b5f4a8a88696d95cef8c4da2adc6afb4aa352affef3732e463a47973d2693e9efd345d
6
+ metadata.gz: 627ebefe50230f6274294750207d30b8e2968189a7d02d992c506f3fb63af5511297c7cae042447201ca73fc073b3bb3405d7175ccb2395b3c5d10a249bb5610
7
+ data.tar.gz: 8fea34f5b1c9985b544f7c789b8aefb3f7745a4c5b3650a4c90ac2f897c72436fb4894887162d1129b4dc4432cef59c6e164afb568716e8883422c403a6abfe4
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ 0.1.10 (2015-07-04)
2
+
3
+ * New - (basic) update_item support, for atomic PUT and DELETE actions, no support for ADD action yet
4
+
1
5
  0.1.9 (2015-07-01)
2
6
  -----------------
3
7
 
@@ -60,7 +60,10 @@ module TinyDyno
60
60
  if attributes.nil?
61
61
  return false
62
62
  else
63
- self.new(attributes)
63
+ record = self.new(attributes)
64
+ record.instance_variable_set(:@new_record, false)
65
+ record.instance_variable_set(:@changed_attributes, {})
66
+ record
64
67
  end
65
68
  end
66
69
 
@@ -12,62 +12,80 @@ module TinyDyno
12
12
  return false
13
13
  end
14
14
  else
15
- request_update_item(options)
15
+ if request_update_item(options)
16
+ changes_applied
17
+ return true
18
+ else
19
+ return false
20
+ end
16
21
  end
17
22
  end
18
23
 
19
24
  private
20
25
 
21
26
  def request_put_item(options)
22
- request = request_as_new_record(build_item_request(options))
27
+ request = request_as_new_record(build_put_item_request)
23
28
  return(TinyDyno::Adapter.put_item(put_item_request: request))
24
29
  end
25
30
 
26
- # The target structure as per
27
- # http://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html#put_item-instance_method
28
- #
29
- # resp = client.put_item({
30
- # table_name: "TableName", # required
31
- # item: { # required
32
- # "AttributeName" => "value", # value <Hash,Array,String,Numeric,Boolean,IO,Set,nil>
33
- # },
34
- # expected: {
35
- # "AttributeName" => {
36
- # value: "value", # value <Hash,Array,String,Numeric,Boolean,IO,Set,nil>
37
- # exists: true,
38
- # comparison_operator: "EQ", # accepts EQ, NE, IN, LE, LT, GE, GT, BETWEEN, NOT_NULL, NULL, CONTAINS, NOT_CONTAINS, BEGINS_WITH
39
- # attribute_value_list: ["value"], # value <Hash,Array,String,Numeric,Boolean,IO,Set,nil>
40
- # },
41
- # },
42
- # return_values: "NONE", # accepts NONE, ALL_OLD, UPDATED_OLD, ALL_NEW, UPDATED_NEW
43
- # return_consumed_capacity: "INDEXES", # accepts INDEXES, TOTAL, NONE
44
- # return_item_collection_metrics: "SIZE", # accepts SIZE, NONE
45
- # conditional_operator: "AND", # accepts AND, OR
46
- # condition_expression: "ConditionExpression",
47
- # expression_attribute_names: {
48
- # "ExpressionAttributeNameVariable" => "AttributeName",
49
- # },
50
- # expression_attribute_values: {
51
- # "ExpressionAttributeValueVariable" => "value", # value <Hash,Array,String,Numeric,Boolean,IO,Set,nil>
52
- # },
53
- # })
54
- def build_item_request(options)
31
+ def request_update_item(options)
32
+ request = build_update_item_request
33
+ return(TinyDyno::Adapter.update_item(update_item_request: request))
34
+ end
35
+
36
+ def build_put_item_request
55
37
  {
56
38
  table_name: self.class.table_name,
57
39
  item: build_item_request_entries
58
40
  }
59
41
  end
60
42
 
43
+ def build_update_item_request
44
+ {
45
+ key: hash_key_as_selector,
46
+ table_name: self.class.table_name,
47
+ attribute_updates: build_attribute_updates
48
+ }
49
+ end
50
+
61
51
  def build_item_request_entries
62
52
  item_entries = {}
63
- attributes.each do |k,v|
64
- item_entries[k] = v
65
- end
53
+ attributes.each { |k,v| item_entries[k] = v }
66
54
  item_entries
67
55
  end
68
56
 
69
- def request_update_item(options)
70
-
57
+ # attribute_updates: {
58
+ # "AttributeName" => {
59
+ # value: "value", # value <Hash,Array,String,Numeric,Boolean,IO,Set,nil>
60
+ # action: "ADD", # accepts ADD, PUT, DELETE
61
+ # },
62
+ def build_attribute_updates
63
+ change_record = []
64
+ changes.keys.each do |change_key|
65
+ if self.class.attribute_names.include?(change_key)
66
+ change_record << {:"#{ change_key}" => changes[change_key]}
67
+ end
68
+ end
69
+ # keep this simple for now
70
+ # I don't see (yet) how to map the possible operations on dynamodb items
71
+ # into activerecord compatible schemas
72
+ # extend as use cases arise
73
+ # specification by example ...
74
+ attribute_updates = {}
75
+ change_record.each do |change|
76
+ change_key = change.keys.first
77
+ if change[change_key][1].nil?
78
+ attribute_updates[change_key] = {
79
+ action: 'DELETE'
80
+ }
81
+ else
82
+ attribute_updates[change_key] = {
83
+ value: change[change_key][1],
84
+ action: 'PUT'
85
+ }
86
+ end
87
+ end
88
+ attribute_updates
71
89
  end
72
90
 
73
91
  module ClassMethods
@@ -1,3 +1,3 @@
1
1
  module TinyDyno
2
- VERSION = '0.1.9'
2
+ VERSION = '0.1.10'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny_dyno
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Gerschner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-02 00:00:00.000000000 Z
11
+ date: 2015-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler