ocean-dynamo 0.3.1 → 0.3.2
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/README.rdoc +4 -4
- data/lib/ocean-dynamo/attributes.rb +13 -7
- data/lib/ocean-dynamo/persistence.rb +4 -4
- data/lib/ocean-dynamo/queries.rb +5 -0
- data/lib/ocean-dynamo/schema.rb +8 -6
- data/lib/ocean-dynamo/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: 6f942e71fcd88e1e0971e48f931e62a686f1cf28
|
4
|
+
data.tar.gz: bb383ce780b0d04419de134073ea56d0bb6d3af7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0f6617f8ed0224199f4b935f8faaa1e4ab54fa70086f6fec6834db564dbf4c61caad45f7de2a9a0a4d79aeb7199c17f30069864fbd383311cd304670210bca8
|
7
|
+
data.tar.gz: 6b6bcc33a0eb6f471f0d0d9654f12199b5255babf20c1a4028ef352b7e2ec32bbfffbf5b7db5d609ff807a693b9c0ff1ad190de47eb8735fe0e0f29255408917
|
data/README.rdoc
CHANGED
@@ -40,7 +40,7 @@ The following example shows the syntax.
|
|
40
40
|
|
41
41
|
class AsyncJob < OceanDynamo::Base
|
42
42
|
|
43
|
-
dynamo_schema do
|
43
|
+
dynamo_schema(:uuid) do
|
44
44
|
attribute :credentials, :string
|
45
45
|
attribute :token
|
46
46
|
attribute :steps, :serialized, default: []
|
@@ -62,8 +62,8 @@ The following example shows the syntax.
|
|
62
62
|
|
63
63
|
Each attribute has a name, a type (+:string+, +:integer+, +:float+, +:datetime+, +:boolean+,
|
64
64
|
or +:serialized+) where +:string+ is the default. Each attribute also optionally has a default
|
65
|
-
value, which can be a Proc. The hash key attribute is by default +:
|
66
|
-
|
65
|
+
value, which can be a Proc. The hash key attribute is by default +:id+ (overridden as :uuid in
|
66
|
+
the example above) and is a +:string+. The keys can also be explicitly declared.
|
67
67
|
|
68
68
|
The +:string+, +:integer+, +:float+ and +:datetime+ types can also store sets of their type.
|
69
69
|
Sets are represented as arrays, may not contain duplicates and may not be empty.
|
@@ -74,7 +74,7 @@ value will return the empty string, <tt>""</tt>.
|
|
74
74
|
Also, dynamo_schema takes args and many options. Here's the full syntax:
|
75
75
|
|
76
76
|
dynamo_schema(
|
77
|
-
table_hash_key = :
|
77
|
+
table_hash_key = :id, # The name of the hash key attribute
|
78
78
|
table_range_key = nil, # The name of the range key attribute (or nil)
|
79
79
|
table_name: compute_table_name, # The basename of the DynamoDB table
|
80
80
|
table_name_prefix: nil, # A basename prefix string or nil
|
@@ -22,7 +22,7 @@ module OceanDynamo
|
|
22
22
|
@new_record = true
|
23
23
|
raise UnknownPrimaryKey unless table_hash_key
|
24
24
|
end
|
25
|
-
attrs &&
|
25
|
+
attrs && attrs.delete_if { |k, v| !fields.has_key?(k) }
|
26
26
|
super(attrs)
|
27
27
|
end
|
28
28
|
|
@@ -38,7 +38,7 @@ module OceanDynamo
|
|
38
38
|
|
39
39
|
|
40
40
|
def id
|
41
|
-
|
41
|
+
read_attribute(table_hash_key)
|
42
42
|
end
|
43
43
|
|
44
44
|
|
@@ -46,6 +46,10 @@ module OceanDynamo
|
|
46
46
|
write_attribute(table_hash_key, value)
|
47
47
|
end
|
48
48
|
|
49
|
+
def id?
|
50
|
+
read_attribute(table_hash_key).present?
|
51
|
+
end
|
52
|
+
|
49
53
|
|
50
54
|
def read_attribute_for_validation(key)
|
51
55
|
@attributes[key.to_s]
|
@@ -54,16 +58,18 @@ module OceanDynamo
|
|
54
58
|
|
55
59
|
def read_attribute(attr_name)
|
56
60
|
attr_name = attr_name.to_s
|
57
|
-
if attr_name == 'id'
|
58
|
-
|
61
|
+
attr_name = table_hash_key.to_s if attr_name == 'id'
|
62
|
+
if fields.has_key?(attr_name)
|
63
|
+
@attributes[attr_name]
|
64
|
+
else
|
65
|
+
raise ActiveModel::MissingAttributeError, "can't read unknown attribute `#{attr_ name}"
|
59
66
|
end
|
60
|
-
@attributes[attr_name] # Type cast!
|
61
67
|
end
|
62
68
|
|
63
69
|
|
64
70
|
def write_attribute(attr_name, value)
|
65
71
|
attr_name = attr_name.to_s
|
66
|
-
attr_name = table_hash_key.to_s if attr_name == 'id'
|
72
|
+
attr_name = table_hash_key.to_s if attr_name == 'id'
|
67
73
|
if fields.has_key?(attr_name)
|
68
74
|
@attributes[attr_name] = type_cast_attribute_for_write(attr_name, value)
|
69
75
|
else
|
@@ -80,7 +86,7 @@ module OceanDynamo
|
|
80
86
|
end
|
81
87
|
|
82
88
|
|
83
|
-
def assign_attributes(values)
|
89
|
+
def assign_attributes(values, without_protection: false)
|
84
90
|
return if values.blank?
|
85
91
|
values = values.stringify_keys
|
86
92
|
# if values.respond_to?(:permitted?)
|
@@ -83,14 +83,14 @@ module OceanDynamo
|
|
83
83
|
end
|
84
84
|
|
85
85
|
|
86
|
-
def update_attributes(attrs={})
|
87
|
-
assign_attributes(attrs)
|
86
|
+
def update_attributes(attrs={}, options={})
|
87
|
+
assign_attributes(attrs, options)
|
88
88
|
save
|
89
89
|
end
|
90
90
|
|
91
91
|
|
92
|
-
def update_attributes!(attrs={})
|
93
|
-
assign_attributes(attrs)
|
92
|
+
def update_attributes!(attrs={}, options={})
|
93
|
+
assign_attributes(attrs, options)
|
94
94
|
save!
|
95
95
|
end
|
96
96
|
|
data/lib/ocean-dynamo/queries.rb
CHANGED
data/lib/ocean-dynamo/schema.rb
CHANGED
@@ -2,7 +2,7 @@ module OceanDynamo
|
|
2
2
|
class Base
|
3
3
|
|
4
4
|
|
5
|
-
def self.dynamo_schema(table_hash_key=:
|
5
|
+
def self.dynamo_schema(table_hash_key=:id,
|
6
6
|
table_range_key=nil,
|
7
7
|
table_name: compute_table_name,
|
8
8
|
table_name_prefix: nil,
|
@@ -32,15 +32,17 @@ module OceanDynamo
|
|
32
32
|
self.timestamp_attributes = timestamps
|
33
33
|
# Init
|
34
34
|
self.fields = HashWithIndifferentAccess.new
|
35
|
-
attribute table_hash_key, :string, default:
|
35
|
+
attribute table_hash_key, :string, default: ""
|
36
36
|
timestamp_attributes.each { |name| attribute name, :datetime } if timestamp_attributes
|
37
|
-
attribute(lock_attribute, :integer, default: 0) if
|
37
|
+
attribute(lock_attribute, :integer, default: 0) if locking
|
38
38
|
block.call
|
39
39
|
# Define attribute accessors
|
40
40
|
fields.each do |name, md|
|
41
|
-
|
42
|
-
|
43
|
-
self.class_eval "def #{name}
|
41
|
+
name = name.to_s
|
42
|
+
# We define accessors even if the name is 'id' (for which we already have methods)
|
43
|
+
self.class_eval "def #{name}; read_attribute('#{name}'); end"
|
44
|
+
self.class_eval "def #{name}=(value); write_attribute('#{name}', value); end"
|
45
|
+
self.class_eval "def #{name}?; read_attribute('#{name}').present?; end"
|
44
46
|
end
|
45
47
|
# Connect to AWS
|
46
48
|
establish_db_connection if connect == true
|
data/lib/ocean-dynamo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ocean-dynamo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Bengtson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|