aws-record 2.0.1 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7800be1064f00422e1512670962d2af0b0579aa
4
- data.tar.gz: 3ca62f412897b8e315affc5b50244be4e770a64b
3
+ metadata.gz: 7d74cea18f658e37fa6d0859826cbf76cb013a17
4
+ data.tar.gz: 8c624c68f54659a10c48231a70be86608254fe49
5
5
  SHA512:
6
- metadata.gz: 4d4889d7a3a5d7903eaf4c1d90b704e366f8768246641e264fbe8d7491bec45ebba2c0eccfdf1c3d6c1da5d320773f00ce2ef6ec9a9b8d89c56796ffa41c1d87
7
- data.tar.gz: e1838d4e4dfda379da766e68de68618f9832520b05e62aa8dfb55eb3916d3861b35a1b2ae2f456d8e0f670ee9f5a109336a5e48ba1d488cbc1d79d11581c9c63
6
+ metadata.gz: b420c83918fc9306243df3e2b2f3cbb2226893763317bd84f97851c1cd9f7e34d1136929546417f627328ad275f4eb50e8621aa428ca49aa760e2d5e9a005b84
7
+ data.tar.gz: 1139b5b759c65e1b6387046ba0ad139cb695e438f1e8dc5cab7d343a74a0473f3e24da5b173cb9e5bfa227f3648401e276462a616a70a30bb4ff7830c91f572a
@@ -33,6 +33,7 @@ require_relative 'aws-record/record/marshalers/integer_marshaler'
33
33
  require_relative 'aws-record/record/marshalers/float_marshaler'
34
34
  require_relative 'aws-record/record/marshalers/date_marshaler'
35
35
  require_relative 'aws-record/record/marshalers/date_time_marshaler'
36
+ require_relative 'aws-record/record/marshalers/time_marshaler'
36
37
  require_relative 'aws-record/record/marshalers/list_marshaler'
37
38
  require_relative 'aws-record/record/marshalers/map_marshaler'
38
39
  require_relative 'aws-record/record/marshalers/string_set_marshaler'
@@ -219,6 +219,27 @@ module Aws
219
219
  attr(name, Marshalers::DateTimeMarshaler.new(opts), opts)
220
220
  end
221
221
 
222
+ # Define a time-type attribute for your model.
223
+ #
224
+ # @param [Symbol] name Name of this attribute. It should be a name that
225
+ # is safe to use as a method.
226
+ # @param [Hash] opts
227
+ # @option opts [Boolean] :hash_key Set to true if this attribute is
228
+ # the hash key for the table.
229
+ # @option opts [Boolean] :range_key Set to true if this attribute is
230
+ # the range key for the table.
231
+ # @option opts [Boolean] :persist_nil Optional attribute used to
232
+ # indicate whether nil values should be persisted. If true, explicitly
233
+ # set nil values will be saved to DynamoDB as a "null" type. If false,
234
+ # nil values will be ignored and not persisted. By default, is false.
235
+ # @option opts [Object] :default_value Optional attribute used to
236
+ # define a "default value" to be used if the attribute's value on an
237
+ # item is nil or not set at persistence time.
238
+ def time_attr(name, opts = {})
239
+ opts[:dynamodb_type] = "S"
240
+ attr(name, Marshalers::TimeMarshaler.new(opts), opts)
241
+ end
242
+
222
243
  # Define a list-type attribute for your model.
223
244
  #
224
245
  # Lists do not have to be homogeneous, but they do have to be types that
@@ -339,12 +360,12 @@ module Aws
339
360
  attr(name, Marshalers::NumericSetMarshaler.new(opts), opts)
340
361
  end
341
362
 
342
- # @return [Symbol,nil]
363
+ # @return [Symbol,nil] The symbolic name of the table's hash key.
343
364
  def hash_key
344
365
  @keys.hash_key
345
366
  end
346
367
 
347
- # @return [Symbol,nil]
368
+ # @return [Symbol,nil] The symbloc name of the table's range key, or nil if there is no range key.
348
369
  def range_key
349
370
  @keys.range_key
350
371
  end
@@ -0,0 +1,73 @@
1
+ # Copyright 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 'time'
15
+
16
+ module Aws
17
+ module Record
18
+ module Marshalers
19
+
20
+ class TimeMarshaler
21
+ def initialize(opts = {})
22
+ @formatter = opts[:formatter] || Iso8601Formatter
23
+ @use_local_time = opts[:use_local_time] ? true : false
24
+ end
25
+
26
+ def type_cast(raw_value)
27
+ value = _format(raw_value)
28
+ if !@use_local_time && value.is_a?(::Time)
29
+ value.utc
30
+ else
31
+ value
32
+ end
33
+ end
34
+
35
+ def serialize(raw_value)
36
+ time = type_cast(raw_value)
37
+ if time.nil?
38
+ nil
39
+ elsif time.is_a?(::Time)
40
+ @formatter.format(time)
41
+ else
42
+ msg = "expected a Time value or nil, got #{time.class}"
43
+ raise ArgumentError, msg
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def _format(raw_value)
50
+ case raw_value
51
+ when nil
52
+ nil
53
+ when ''
54
+ nil
55
+ when ::Time
56
+ raw_value
57
+ when Integer # timestamp
58
+ ::Time.at(raw_value)
59
+ else # Date, DateTime, or String
60
+ ::Time.parse(raw_value.to_s)
61
+ end
62
+ end
63
+ end
64
+
65
+ module Iso8601Formatter
66
+ def self.format(time)
67
+ time.iso8601
68
+ end
69
+ end
70
+
71
+ end
72
+ end
73
+ end
@@ -31,7 +31,7 @@ module Aws
31
31
  def initialize(model, opts = {})
32
32
  _assert_model_valid(model)
33
33
  @model = model
34
- @client = opts[:client] || Aws::DynamoDB::Client.new
34
+ @client = opts[:client] || model.dynamodb_client || Aws::DynamoDB::Client.new
35
35
  end
36
36
 
37
37
  # This method calls
@@ -13,6 +13,6 @@
13
13
 
14
14
  module Aws
15
15
  module Record
16
- VERSION = '2.0.1'
16
+ VERSION = '2.0.2'
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: 2.0.1
4
+ version: 2.0.2
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: 2017-10-27 00:00:00.000000000 Z
11
+ date: 2018-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-dynamodb
@@ -51,6 +51,7 @@ files:
51
51
  - lib/aws-record/record/marshalers/numeric_set_marshaler.rb
52
52
  - lib/aws-record/record/marshalers/string_marshaler.rb
53
53
  - lib/aws-record/record/marshalers/string_set_marshaler.rb
54
+ - lib/aws-record/record/marshalers/time_marshaler.rb
54
55
  - lib/aws-record/record/model_attributes.rb
55
56
  - lib/aws-record/record/query.rb
56
57
  - lib/aws-record/record/secondary_indexes.rb