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 +4 -4
- data/CHANGES.md +4 -0
- data/lib/tiny_dyno/document.rb +4 -1
- data/lib/tiny_dyno/persistable.rb +54 -36
- data/lib/tiny_dyno/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a5a334e766b682c0dd8efe2eb7ac34fc4cf85ce
|
4
|
+
data.tar.gz: 1e7428905fab9f8cf20ab1d30ce0dc3446badc47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 627ebefe50230f6274294750207d30b8e2968189a7d02d992c506f3fb63af5511297c7cae042447201ca73fc073b3bb3405d7175ccb2395b3c5d10a249bb5610
|
7
|
+
data.tar.gz: 8fea34f5b1c9985b544f7c789b8aefb3f7745a4c5b3650a4c90ac2f897c72436fb4894887162d1129b4dc4432cef59c6e164afb568716e8883422c403a6abfe4
|
data/CHANGES.md
CHANGED
data/lib/tiny_dyno/document.rb
CHANGED
@@ -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(
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
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
|
-
|
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
|
data/lib/tiny_dyno/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2015-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|