aws-record 2.10.0 → 2.11.0

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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +335 -0
  3. data/LICENSE +202 -0
  4. data/VERSION +1 -0
  5. data/lib/aws-record/record/attribute.rb +9 -21
  6. data/lib/aws-record/record/attributes.rb +68 -78
  7. data/lib/aws-record/record/batch.rb +13 -12
  8. data/lib/aws-record/record/batch_read.rb +5 -2
  9. data/lib/aws-record/record/batch_write.rb +1 -12
  10. data/lib/aws-record/record/buildable_search.rb +33 -28
  11. data/lib/aws-record/record/client_configuration.rb +10 -21
  12. data/lib/aws-record/record/dirty_tracking.rb +30 -44
  13. data/lib/aws-record/record/errors.rb +1 -13
  14. data/lib/aws-record/record/item_collection.rb +5 -16
  15. data/lib/aws-record/record/item_data.rb +4 -18
  16. data/lib/aws-record/record/item_operations.rb +86 -93
  17. data/lib/aws-record/record/key_attributes.rb +1 -14
  18. data/lib/aws-record/record/marshalers/boolean_marshaler.rb +2 -16
  19. data/lib/aws-record/record/marshalers/date_marshaler.rb +1 -15
  20. data/lib/aws-record/record/marshalers/date_time_marshaler.rb +2 -14
  21. data/lib/aws-record/record/marshalers/epoch_time_marshaler.rb +1 -14
  22. data/lib/aws-record/record/marshalers/float_marshaler.rb +3 -19
  23. data/lib/aws-record/record/marshalers/integer_marshaler.rb +3 -19
  24. data/lib/aws-record/record/marshalers/list_marshaler.rb +2 -16
  25. data/lib/aws-record/record/marshalers/map_marshaler.rb +2 -16
  26. data/lib/aws-record/record/marshalers/numeric_set_marshaler.rb +3 -16
  27. data/lib/aws-record/record/marshalers/string_marshaler.rb +2 -16
  28. data/lib/aws-record/record/marshalers/string_set_marshaler.rb +3 -16
  29. data/lib/aws-record/record/marshalers/time_marshaler.rb +1 -14
  30. data/lib/aws-record/record/model_attributes.rb +14 -35
  31. data/lib/aws-record/record/query.rb +7 -21
  32. data/lib/aws-record/record/secondary_indexes.rb +23 -42
  33. data/lib/aws-record/record/table_config.rb +52 -74
  34. data/lib/aws-record/record/table_migration.rb +43 -66
  35. data/lib/aws-record/record/transactions.rb +67 -38
  36. data/lib/aws-record/record/version.rb +2 -13
  37. data/lib/aws-record/record.rb +30 -49
  38. metadata +14 -5
@@ -1,23 +1,10 @@
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.
1
+ # frozen_string_literal: true
13
2
 
14
3
  module Aws
15
4
  module Record
16
5
  module Marshalers
17
-
18
6
  class ListMarshaler
19
- def initialize(opts = {})
20
- end
7
+ def initialize(opts = {}); end
21
8
 
22
9
  def type_cast(raw_value)
23
10
  case raw_value
@@ -50,7 +37,6 @@ module Aws
50
37
  end
51
38
  end
52
39
  end
53
-
54
40
  end
55
41
  end
56
42
  end
@@ -1,23 +1,10 @@
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.
1
+ # frozen_string_literal: true
13
2
 
14
3
  module Aws
15
4
  module Record
16
5
  module Marshalers
17
-
18
6
  class MapMarshaler
19
- def initialize(opts = {})
20
- end
7
+ def initialize(opts = {}); end
21
8
 
22
9
  def type_cast(raw_value)
23
10
  case raw_value
@@ -50,7 +37,6 @@ module Aws
50
37
  end
51
38
  end
52
39
  end
53
-
54
40
  end
55
41
  end
56
42
  end
@@ -1,23 +1,10 @@
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.
1
+ # frozen_string_literal: true
13
2
 
14
3
  module Aws
15
4
  module Record
16
5
  module Marshalers
17
-
18
6
  class NumericSetMarshaler
19
- def initialize(opts = {})
20
- end
7
+ def initialize(opts = {}); end
21
8
 
22
9
  def type_cast(raw_value)
23
10
  case raw_value
@@ -53,6 +40,7 @@ module Aws
53
40
  end
54
41
 
55
42
  private
43
+
56
44
  def _as_numeric(set)
57
45
  set.collect! do |item|
58
46
  if item.is_a?(Numeric)
@@ -63,7 +51,6 @@ module Aws
63
51
  end
64
52
  end
65
53
  end
66
-
67
54
  end
68
55
  end
69
56
  end
@@ -1,23 +1,10 @@
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.
1
+ # frozen_string_literal: true
13
2
 
14
3
  module Aws
15
4
  module Record
16
5
  module Marshalers
17
-
18
6
  class StringMarshaler
19
- def initialize(opts = {})
20
- end
7
+ def initialize(opts = {}); end
21
8
 
22
9
  def type_cast(raw_value)
23
10
  case raw_value
@@ -46,7 +33,6 @@ module Aws
46
33
  end
47
34
  end
48
35
  end
49
-
50
36
  end
51
37
  end
52
38
  end
@@ -1,23 +1,10 @@
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.
1
+ # frozen_string_literal: true
13
2
 
14
3
  module Aws
15
4
  module Record
16
5
  module Marshalers
17
-
18
6
  class StringSetMarshaler
19
- def initialize(opts = {})
20
- end
7
+ def initialize(opts = {}); end
21
8
 
22
9
  def type_cast(raw_value)
23
10
  case raw_value
@@ -53,6 +40,7 @@ module Aws
53
40
  end
54
41
 
55
42
  private
43
+
56
44
  def _as_strings(set)
57
45
  set.collect! do |item|
58
46
  if item.is_a?(String)
@@ -63,7 +51,6 @@ module Aws
63
51
  end
64
52
  end
65
53
  end
66
-
67
54
  end
68
55
  end
69
56
  end
@@ -1,22 +1,10 @@
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.
1
+ # frozen_string_literal: true
13
2
 
14
3
  require 'time'
15
4
 
16
5
  module Aws
17
6
  module Record
18
7
  module Marshalers
19
-
20
8
  class TimeMarshaler
21
9
  def initialize(opts = {})
22
10
  @formatter = opts[:formatter] || Iso8601Formatter
@@ -67,7 +55,6 @@ module Aws
67
55
  time.iso8601
68
56
  end
69
57
  end
70
-
71
58
  end
72
59
  end
73
60
  end
@@ -1,19 +1,7 @@
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.
1
+ # frozen_string_literal: true
13
2
 
14
3
  module Aws
15
4
  module Record
16
-
17
5
  # @api private
18
6
  class ModelAttributes
19
7
  attr_reader :attributes, :storage_attributes
@@ -32,7 +20,7 @@ module Aws
32
20
  attribute
33
21
  end
34
22
 
35
- def register_superclass_attribute (name, attribute)
23
+ def register_superclass_attribute(name, attribute)
36
24
  _new_attr_validation(name, attribute)
37
25
  @attributes[name] = attribute.dup
38
26
  @storage_attributes[attribute.database_name] = name
@@ -56,6 +44,7 @@ module Aws
56
44
  end
57
45
 
58
46
  private
47
+
59
48
  def _new_attr_validation(name, attribute)
60
49
  _validate_attr_name(name)
61
50
  _check_for_naming_collisions(name, attribute.database_name)
@@ -64,43 +53,33 @@ module Aws
64
53
 
65
54
  def _validate_attr_name(name)
66
55
  unless name.is_a?(Symbol)
67
- raise ArgumentError.new("Must use symbolized :name attribute.")
56
+ raise ArgumentError, 'Must use symbolized :name attribute.'
68
57
  end
69
58
  if @attributes[name]
70
- raise Errors::NameCollision.new(
71
- "Cannot overwrite existing attribute #{name}"
72
- )
59
+ raise Errors::NameCollision, "Cannot overwrite existing attribute #{name}"
73
60
  end
74
61
  end
75
62
 
76
63
  def _check_if_reserved(name)
77
64
  if @model_class.instance_methods.include?(name)
78
- raise Errors::ReservedName.new(
79
- "Cannot name an attribute #{name}, that would collide with an"\
80
- " existing instance method."
81
- )
65
+ raise Errors::ReservedName, "Cannot name an attribute #{name}, that would collide with an"\
66
+ ' existing instance method.'
82
67
  end
83
68
  end
84
69
 
85
70
  def _check_for_naming_collisions(name, storage_name)
86
71
  if @attributes[storage_name.to_sym]
87
- raise Errors::NameCollision.new(
88
- "Custom storage name #{storage_name} already exists as an"\
89
- " attribute name in #{@attributes}"
90
- )
72
+ raise Errors::NameCollision, "Custom storage name #{storage_name} already exists as an"\
73
+ " attribute name in #{@attributes}"
91
74
  elsif @storage_attributes[name.to_s]
92
- raise Errors::NameCollision.new(
93
- "Attribute name #{name} already exists as a custom storage"\
94
- " name in #{@storage_attributes}"
95
- )
75
+ raise Errors::NameCollision, "Attribute name #{name} already exists as a custom storage"\
76
+ " name in #{@storage_attributes}"
96
77
  elsif @storage_attributes[storage_name]
97
- raise Errors::NameCollision.new(
98
- "Custom storage name #{storage_name} already in use in"\
99
- " #{@storage_attributes}"
100
- )
78
+ raise Errors::NameCollision, "Custom storage name #{storage_name} already in use in"\
79
+ " #{@storage_attributes}"
80
+
101
81
  end
102
82
  end
103
83
  end
104
-
105
84
  end
106
85
  end
@@ -1,31 +1,18 @@
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.
1
+ # frozen_string_literal: true
13
2
 
14
3
  module Aws
15
4
  module Record
16
5
  module Query
17
-
18
6
  # @api private
19
7
  def self.included(sub_class)
20
8
  sub_class.extend(QueryClassMethods)
21
9
  end
22
10
 
23
11
  module QueryClassMethods
24
-
25
12
  # This method calls
26
- # {http://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html#query-instance_method Aws::DynamoDB::Client#query},
27
- # populating the +:table_name+ parameter from the model class, and
28
- # combining this with the other parameters you provide.
13
+ # {http://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html#query-instance_method
14
+ # Aws::DynamoDB::Client#query}, populating the +:table_name+ parameter from the model
15
+ # class, and combining this with the other parameters you provide.
29
16
  #
30
17
  # @example A query with key and filter expressions:
31
18
  # # Example model class
@@ -66,9 +53,9 @@ module Aws
66
53
  end
67
54
 
68
55
  # This method calls
69
- # {http://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html#scan-instance_method Aws::DynamoDB::Client#scan},
70
- # populating the +:table_name+ parameter from the model class, and
71
- # combining this with the other parameters you provide.
56
+ # {http://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html#scan-instance_method
57
+ # Aws::DynamoDB::Client#scan}, populating the +:table_name+ parameter from the model
58
+ # class, and combining this with the other parameters you provide.
72
59
  #
73
60
  # @example A scan with a filter expression:
74
61
  # # Example model class
@@ -151,7 +138,6 @@ module Aws
151
138
  )
152
139
  end
153
140
  end
154
-
155
141
  end
156
142
  end
157
143
  end
@@ -1,40 +1,26 @@
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.
1
+ # frozen_string_literal: true
13
2
 
14
3
  module Aws
15
4
  module Record
16
5
  module SecondaryIndexes
17
-
18
6
  # @api private
19
7
  def self.included(sub_class)
20
- sub_class.instance_variable_set("@local_secondary_indexes", {})
21
- sub_class.instance_variable_set("@global_secondary_indexes", {})
8
+ sub_class.instance_variable_set('@local_secondary_indexes', {})
9
+ sub_class.instance_variable_set('@global_secondary_indexes', {})
22
10
  sub_class.extend(SecondaryIndexesClassMethods)
23
- if Aws::Record.extends_record?(sub_class)
24
- inherit_indexes(sub_class)
25
- end
11
+ inherit_indexes(sub_class) if Aws::Record.extends_record?(sub_class)
26
12
  end
27
13
 
28
- private
29
14
  def self.inherit_indexes(klass)
30
- superclass_lsi = klass.superclass.instance_variable_get("@local_secondary_indexes").dup
31
- superclass_gsi = klass.superclass.instance_variable_get("@global_secondary_indexes").dup
32
- klass.instance_variable_set("@local_secondary_indexes", superclass_lsi)
33
- klass.instance_variable_set("@global_secondary_indexes", superclass_gsi)
15
+ superclass_lsi = klass.superclass.instance_variable_get('@local_secondary_indexes').dup
16
+ superclass_gsi = klass.superclass.instance_variable_get('@global_secondary_indexes').dup
17
+ klass.instance_variable_set('@local_secondary_indexes', superclass_lsi)
18
+ klass.instance_variable_set('@global_secondary_indexes', superclass_gsi)
34
19
  end
35
20
 
36
- module SecondaryIndexesClassMethods
21
+ private_class_method :inherit_indexes
37
22
 
23
+ module SecondaryIndexesClassMethods
38
24
  # Creates a local secondary index for the model. Learn more about Local
39
25
  # Secondary Indexes in the
40
26
  # {http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LSI.html Amazon DynamoDB Developer Guide}.
@@ -75,7 +61,7 @@ module Aws
75
61
  global_secondary_indexes[name] = opts
76
62
  end
77
63
 
78
- # Returns hash of local secondary index names to the indexs attributes.
64
+ # Returns hash of local secondary index names to the index's attributes.
79
65
  #
80
66
  # *Note*: +local_secondary_indexes+ is inherited from a parent model when {#local_secondary_index}
81
67
  # is explicitly specified in the parent.
@@ -85,7 +71,7 @@ module Aws
85
71
  @local_secondary_indexes
86
72
  end
87
73
 
88
- # Returns hash of global secondary index names to the indexs attributes.
74
+ # Returns hash of global secondary index names to the index's attributes.
89
75
  #
90
76
  # *Note*: +global_secondary_indexes+ is inherited from a parent model when {#global_secondary_index}
91
77
  # is explicitly specified in the parent.
@@ -110,6 +96,7 @@ module Aws
110
96
  end
111
97
 
112
98
  private
99
+
113
100
  def _migration_format_indexes(indexes)
114
101
  return nil if indexes.empty?
115
102
  mfi = indexes.collect do |name, opts|
@@ -127,12 +114,12 @@ module Aws
127
114
 
128
115
  def _si_key_schema(opts)
129
116
  key_schema = [{
130
- key_type: "HASH",
117
+ key_type: 'HASH',
131
118
  attribute_name: @attributes.storage_name_for(opts[:hash_key])
132
119
  }]
133
120
  if opts[:range_key]
134
121
  key_schema << {
135
- key_type: "RANGE",
122
+ key_type: 'RANGE',
136
123
  attribute_name: @attributes.storage_name_for(opts[:range_key])
137
124
  }
138
125
  end
@@ -143,9 +130,7 @@ module Aws
143
130
  if params[:hash_key] && params[:range_key]
144
131
  _validate_attributes_exist(params[:hash_key], params[:range_key])
145
132
  else
146
- raise ArgumentError.new(
147
- "Local Secondary Indexes require a hash and range key!"
148
- )
133
+ raise ArgumentError, 'Local Secondary Indexes require a hash and range key!'
149
134
  end
150
135
  end
151
136
 
@@ -157,26 +142,22 @@ module Aws
157
142
  _validate_attributes_exist(params[:hash_key])
158
143
  end
159
144
  else
160
- raise ArgumentError.new(
161
- "Global Secondary Indexes require at least a hash key!"
162
- )
145
+ raise ArgumentError, 'Global Secondary Indexes require at least a hash key!'
163
146
  end
164
147
  end
165
148
 
166
149
  def _validate_attributes_exist(*attr_names)
167
- missing = attr_names.select do |attr_name|
168
- !@attributes.present?(attr_name)
150
+ missing = attr_names.reject do |attr_name|
151
+ @attributes.present?(attr_name)
169
152
  end
170
153
  unless missing.empty?
171
- raise ArgumentError.new(
172
- "#{missing.join(", ")} not present in model attributes."\
173
- " Please ensure that attributes are defined in the model"\
174
- " class BEFORE defining an index on those attributes."
175
- )
154
+ raise ArgumentError, "#{missing.join(', ')} not present in model attributes."\
155
+ ' Please ensure that attributes are defined in the model'\
156
+ ' class BEFORE defining an index on those attributes.'
157
+
176
158
  end
177
159
  end
178
160
  end
179
-
180
161
  end
181
162
  end
182
163
  end