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