aws-record 1.0.0.pre.2 → 1.0.0.pre.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f411d61078b7eeb8fbd7081d51c3f41b1c9116ca
4
- data.tar.gz: 073b4953897897aba7298b5ba90e8050a015fcde
3
+ metadata.gz: 9169388f2bc16aa254c9c374304bedfdbf9257b9
4
+ data.tar.gz: b6e10a6ec3c737436eb9667f84ed4a5235dd33ab
5
5
  SHA512:
6
- metadata.gz: ba35bcbfadff82862f5170c428d213c23157307c07ef9325263d877596cb2c32e0a9b65ee150e7492538b67f422c90d3f8112b5d51def09508e55c974ae6944f
7
- data.tar.gz: 9301a70e55fae642dd83c814720ab78543dae3ec12e1c806df096326009308dce7fbb2666a1a8610cd18c69418be9e70d93649b1d2780b42523fb9361c7e04a6
6
+ metadata.gz: 868f158bd20470e096bd40258b5a88670a519637746b95314d0d05a4f9414e05adf631b10904cd99a637a46cd4ba933427f3ef8fd3368c9fbd0d0a8c03c87845
7
+ data.tar.gz: 72faa6654ba4a9b66c59b2c20778cbf1d00635e12ee4aef5b1a561d603613fbc49d817b3e2c48246ee41b15a3f51df2fc4074ea6ac5b3a3eaf6b876e1bc1403a
data/lib/aws-record.rb CHANGED
@@ -28,12 +28,16 @@ module Aws
28
28
  autoload :VERSION, 'aws-record/record/version'
29
29
 
30
30
  module Attributes
31
- autoload :StringMarshaler, 'aws-record/record/attributes/string_marshaler'
32
- autoload :BooleanMarshaler, 'aws-record/record/attributes/boolean_marshaler'
33
- autoload :IntegerMarshaler, 'aws-record/record/attributes/integer_marshaler'
34
- autoload :FloatMarshaler, 'aws-record/record/attributes/float_marshaler'
35
- autoload :DateMarshaler, 'aws-record/record/attributes/date_marshaler'
36
- autoload :DateTimeMarshaler, 'aws-record/record/attributes/date_time_marshaler'
31
+ autoload :StringMarshaler, 'aws-record/record/attributes/string_marshaler'
32
+ autoload :BooleanMarshaler, 'aws-record/record/attributes/boolean_marshaler'
33
+ autoload :IntegerMarshaler, 'aws-record/record/attributes/integer_marshaler'
34
+ autoload :FloatMarshaler, 'aws-record/record/attributes/float_marshaler'
35
+ autoload :DateMarshaler, 'aws-record/record/attributes/date_marshaler'
36
+ autoload :DateTimeMarshaler, 'aws-record/record/attributes/date_time_marshaler'
37
+ autoload :ListMarshaler, 'aws-record/record/attributes/list_marshaler'
38
+ autoload :MapMarshaler, 'aws-record/record/attributes/map_marshaler'
39
+ autoload :StringSetMarshaler, 'aws-record/record/attributes/string_set_marshaler'
40
+ autoload :NumericSetMarshaler, 'aws-record/record/attributes/numeric_set_marshaler'
37
41
  end
38
42
 
39
43
  end
@@ -161,6 +161,120 @@ module Aws
161
161
  attr(name, Attributes::DateTimeMarshaler, opts)
162
162
  end
163
163
 
164
+ # Define a list-type attribute for your model.
165
+ #
166
+ # Lists do not have to be homogeneous, but they do have to be types that
167
+ # the AWS SDK for Ruby V2's DynamoDB client knows how to marshal and
168
+ # unmarshal. Those types are:
169
+ #
170
+ # * Hash
171
+ # * Array
172
+ # * String
173
+ # * Numeric
174
+ # * Boolean
175
+ # * IO
176
+ # * Set
177
+ # * nil
178
+ #
179
+ # Also note that, since lists are heterogeneous, you may lose some
180
+ # precision when marshaling and unmarshaling. For example, symbols will
181
+ # be stringified, but there is no way to return those strings to symbols
182
+ # when the object is read back from DynamoDB.
183
+ #
184
+ # @param [Symbol] name Name of this attribute. It should be a name that
185
+ # is safe to use as a method.
186
+ # @param [Hash] opts
187
+ # @option opts [Boolean] :nil_as_empty_list Set to true if this
188
+ # attribute should interpret nil values as an empty list. If false,
189
+ # nil values will remain nil.
190
+ # @option opts [Boolean] :hash_key Set to true if this attribute is
191
+ # the hash key for the table.
192
+ # @option opts [Boolean] :range_key Set to true if this attribute is
193
+ # the range key for the table.
194
+ def list_attr(name, opts = {})
195
+ opts[:dynamodb_type] = "L"
196
+ attr(name, Attributes::ListMarshaler, opts)
197
+ end
198
+
199
+ # Define a map-type attribute for your model.
200
+ #
201
+ # Maps do not have to be homogeneous, but they do have to use types that
202
+ # the AWS SDK for Ruby V2's DynamoDB client knows how to marshal and
203
+ # unmarshal. Those types are:
204
+ #
205
+ # * Hash
206
+ # * Array
207
+ # * String
208
+ # * Numeric
209
+ # * Boolean
210
+ # * IO
211
+ # * Set
212
+ # * nil
213
+ #
214
+ # Also note that, since maps are heterogeneous, you may lose some
215
+ # precision when marshaling and unmarshaling. For example, symbols will
216
+ # be stringified, but there is no way to return those strings to symbols
217
+ # when the object is read back from DynamoDB.
218
+ #
219
+ # @param [Symbol] name Name of this attribute. It should be a name that
220
+ # is safe to use as a method.
221
+ # @param [Hash] opts
222
+ # @option opts [Boolean] :nil_as_empty_map Set to true if this
223
+ # attribute should interpret nil values as an empty hash. If false,
224
+ # nil values will remain nil.
225
+ # @option opts [Boolean] :hash_key Set to true if this attribute is
226
+ # the hash key for the table.
227
+ # @option opts [Boolean] :range_key Set to true if this attribute is
228
+ # the range key for the table.
229
+ def map_attr(name, opts = {})
230
+ opts[:dynamodb_type] = "M"
231
+ attr(name, Attributes::MapMarshaler, opts)
232
+ end
233
+
234
+ # Define a string set attribute for your model.
235
+ #
236
+ # String sets are homogeneous sets, containing only strings. Note that
237
+ # empty sets cannot be persisted to DynamoDB. Empty sets are valid for
238
+ # aws-record items, but they will not be persisted as sets. nil values
239
+ # from your table, or a lack of value from your table, will be treated
240
+ # as an empty set for item instances. At persistence time, the marshaler
241
+ # will attempt to marshal any non-strings within the set to be String
242
+ # objects.
243
+ #
244
+ # @param [Symbol] name Name of this attribute. It should be a name that
245
+ # is safe to use as a method.
246
+ # @param [Hash] opts
247
+ # @option opts [Boolean] :hash_key Set to true if this attribute is
248
+ # the hash key for the table.
249
+ # @option opts [Boolean] :range_key Set to true if this attribute is
250
+ # the range key for the table.
251
+ def string_set_attr(name, opts = {})
252
+ opts[:dynamodb_type] = "SS"
253
+ attr(name, Attributes::StringSetMarshaler, opts)
254
+ end
255
+
256
+ # Define a numeric set attribute for your model.
257
+ #
258
+ # Numeric sets are homogeneous sets, containing only strings. Note that
259
+ # empty sets cannot be persisted to DynamoDB. Empty sets are valid for
260
+ # aws-record items, but they will not be persisted as sets. nil values
261
+ # from your table, or a lack of value from your table, will be treated
262
+ # as an empty set for item instances. At persistence time, the marshaler
263
+ # will attempt to marshal any non-numerics within the set to be Numeric
264
+ # objects.
265
+ #
266
+ # @param [Symbol] name Name of this attribute. It should be a name that
267
+ # is safe to use as a method.
268
+ # @param [Hash] opts
269
+ # @option opts [Boolean] :hash_key Set to true if this attribute is
270
+ # the hash key for the table.
271
+ # @option opts [Boolean] :range_key Set to true if this attribute is
272
+ # the range key for the table.
273
+ def string_set_attr(name, opts = {})
274
+ opts[:dynamodb_type] = "NS"
275
+ attr(name, Attributes::NumericSetMarshaler, opts)
276
+ end
277
+
164
278
  # @return [Hash] hash of symbolized attribute names to attribute objects
165
279
  def attributes
166
280
  @attributes
@@ -0,0 +1,66 @@
1
+ # Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You may not
4
+ # use this file except in compliance with the License. A copy of the License is
5
+ # located at
6
+ #
7
+ # http://aws.amazon.com/apache2.0/
8
+ #
9
+ # or in the "license" file accompanying this file. This file is distributed on
10
+ # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
+ # or implied. See the License for the specific language governing permissions
12
+ # and limitations under the License.
13
+
14
+ module Aws
15
+ module Record
16
+ module Attributes
17
+ module ListMarshaler
18
+
19
+ class << self
20
+
21
+ def type_cast(raw_value, options = {})
22
+ case raw_value
23
+ when nil
24
+ _cast_nil(raw_value, options)
25
+ when ''
26
+ _cast_nil(raw_value, options)
27
+ when Array
28
+ raw_value
29
+ else
30
+ if raw_value.respond_to?(:to_a)
31
+ raw_value.to_a
32
+ else
33
+ msg = "Don't know how to make #{raw_value} of type"\
34
+ " #{raw_value.class} into an array!"
35
+ raise ArgumentError, msg
36
+ end
37
+ end
38
+ end
39
+
40
+ def serialize(raw_value, options = {})
41
+ list = type_cast(raw_value, options)
42
+ if list.is_a?(Array)
43
+ list
44
+ elsif list.nil?
45
+ nil
46
+ else
47
+ msg = "expected an Array value or nil, got #{list.class}"
48
+ raise ArgumentError, msg
49
+ end
50
+ end
51
+
52
+ private
53
+ def _cast_nil(raw_value, options)
54
+ if options[:nil_as_empty_list]
55
+ []
56
+ else
57
+ nil
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,66 @@
1
+ # Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You may not
4
+ # use this file except in compliance with the License. A copy of the License is
5
+ # located at
6
+ #
7
+ # http://aws.amazon.com/apache2.0/
8
+ #
9
+ # or in the "license" file accompanying this file. This file is distributed on
10
+ # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
+ # or implied. See the License for the specific language governing permissions
12
+ # and limitations under the License.
13
+
14
+ module Aws
15
+ module Record
16
+ module Attributes
17
+ module MapMarshaler
18
+
19
+ class << self
20
+
21
+ def type_cast(raw_value, options = {})
22
+ case raw_value
23
+ when nil
24
+ _cast_nil(raw_value, options)
25
+ when ''
26
+ _cast_nil(raw_value, options)
27
+ when Hash
28
+ raw_value
29
+ else
30
+ if raw_value.respond_to?(:to_h)
31
+ raw_value.to_h
32
+ else
33
+ msg = "Don't know how to make #{raw_value} of type"\
34
+ " #{raw_value.class} into a hash!"
35
+ raise ArgumentError, msg
36
+ end
37
+ end
38
+ end
39
+
40
+ def serialize(raw_value, options = {})
41
+ map = type_cast(raw_value, options)
42
+ if map.is_a?(Hash)
43
+ map
44
+ elsif map.nil?
45
+ nil
46
+ else
47
+ msg = "expected a Hash value or nil, got #{map.class}"
48
+ raise ArgumentError, msg
49
+ end
50
+ end
51
+
52
+ private
53
+ def _cast_nil(raw_value, options)
54
+ if options[:nil_as_empty_map]
55
+ {}
56
+ else
57
+ nil
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,68 @@
1
+ # Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You may not
4
+ # use this file except in compliance with the License. A copy of the License is
5
+ # located at
6
+ #
7
+ # http://aws.amazon.com/apache2.0/
8
+ #
9
+ # or in the "license" file accompanying this file. This file is distributed on
10
+ # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
+ # or implied. See the License for the specific language governing permissions
12
+ # and limitations under the License.
13
+
14
+ require 'bigdecimal'
15
+
16
+ module Aws
17
+ module Record
18
+ module Attributes
19
+ module NumericSetMarshaler
20
+
21
+ class << self
22
+
23
+ def type_cast(raw_value, options = {})
24
+ case raw_value
25
+ when nil
26
+ Set.new
27
+ when ''
28
+ Set.new
29
+ when Set
30
+ _as_numeric(raw_value)
31
+ else
32
+ msg = "Don't know how to make #{raw_value} of type"\
33
+ " #{raw_value.class} into a Numeric Set!"
34
+ raise ArgumentError, msg
35
+ end
36
+ end
37
+
38
+ def serialize(raw_value, options = {})
39
+ set = type_cast(raw_value, options)
40
+ if set.is_a?(Set)
41
+ if set.empty?
42
+ nil
43
+ else
44
+ set
45
+ end
46
+ else
47
+ msg = "expected a Set value or nil, got #{set.class}"
48
+ raise ArgumentError, msg
49
+ end
50
+ end
51
+
52
+ private
53
+ def _as_numeric(set)
54
+ set.collect! do |item|
55
+ if item.is_a?(Numeric)
56
+ item
57
+ else
58
+ BigDecimal.new(item.to_s)
59
+ end
60
+ end
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,66 @@
1
+ # Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You may not
4
+ # use this file except in compliance with the License. A copy of the License is
5
+ # located at
6
+ #
7
+ # http://aws.amazon.com/apache2.0/
8
+ #
9
+ # or in the "license" file accompanying this file. This file is distributed on
10
+ # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
+ # or implied. See the License for the specific language governing permissions
12
+ # and limitations under the License.
13
+
14
+ module Aws
15
+ module Record
16
+ module Attributes
17
+ module StringSetMarshaler
18
+
19
+ class << self
20
+
21
+ def type_cast(raw_value, options = {})
22
+ case raw_value
23
+ when nil
24
+ Set.new
25
+ when ''
26
+ Set.new
27
+ when Set
28
+ _as_strings(raw_value)
29
+ else
30
+ msg = "Don't know how to make #{raw_value} of type"\
31
+ " #{raw_value.class} into a String Set!"
32
+ raise ArgumentError, msg
33
+ end
34
+ end
35
+
36
+ def serialize(raw_value, options = {})
37
+ set = type_cast(raw_value, options)
38
+ if set.is_a?(Set)
39
+ if set.empty?
40
+ nil
41
+ else
42
+ set
43
+ end
44
+ else
45
+ msg = "expected a Set value or nil, got #{set.class}"
46
+ raise ArgumentError, msg
47
+ end
48
+ end
49
+
50
+ private
51
+ def _as_strings(set)
52
+ set.collect! do |item|
53
+ if item.is_a?(String)
54
+ item
55
+ else
56
+ item.to_s
57
+ end
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+ end
65
+ end
66
+ end
@@ -13,6 +13,6 @@
13
13
 
14
14
  module Aws
15
15
  module Record
16
- VERSION = "1.0.0.pre.2"
16
+ VERSION = "1.0.0.pre.3"
17
17
  end
18
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-record
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.2
4
+ version: 1.0.0.pre.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amazon Web Services
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-04 00:00:00.000000000 Z
11
+ date: 2016-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-resources
@@ -40,7 +40,11 @@ files:
40
40
  - lib/aws-record/record/attributes/date_time_marshaler.rb
41
41
  - lib/aws-record/record/attributes/float_marshaler.rb
42
42
  - lib/aws-record/record/attributes/integer_marshaler.rb
43
+ - lib/aws-record/record/attributes/list_marshaler.rb
44
+ - lib/aws-record/record/attributes/map_marshaler.rb
45
+ - lib/aws-record/record/attributes/numeric_set_marshaler.rb
43
46
  - lib/aws-record/record/attributes/string_marshaler.rb
47
+ - lib/aws-record/record/attributes/string_set_marshaler.rb
44
48
  - lib/aws-record/record/errors.rb
45
49
  - lib/aws-record/record/item_collection.rb
46
50
  - lib/aws-record/record/item_operations.rb