dynamoid 3.5.0 → 3.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +35 -4
  3. data/README.md +24 -18
  4. data/lib/dynamoid.rb +1 -0
  5. data/lib/dynamoid/adapter.rb +7 -4
  6. data/lib/dynamoid/adapter_plugin/aws_sdk_v3.rb +14 -11
  7. data/lib/dynamoid/adapter_plugin/aws_sdk_v3/batch_get_item.rb +1 -0
  8. data/lib/dynamoid/adapter_plugin/aws_sdk_v3/create_table.rb +8 -7
  9. data/lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb +3 -2
  10. data/lib/dynamoid/adapter_plugin/aws_sdk_v3/middleware/backoff.rb +1 -0
  11. data/lib/dynamoid/adapter_plugin/aws_sdk_v3/middleware/limit.rb +1 -0
  12. data/lib/dynamoid/adapter_plugin/aws_sdk_v3/middleware/start_key.rb +1 -0
  13. data/lib/dynamoid/adapter_plugin/aws_sdk_v3/query.rb +1 -0
  14. data/lib/dynamoid/adapter_plugin/aws_sdk_v3/scan.rb +1 -0
  15. data/lib/dynamoid/adapter_plugin/aws_sdk_v3/table.rb +1 -0
  16. data/lib/dynamoid/adapter_plugin/aws_sdk_v3/until_past_table_status.rb +1 -0
  17. data/lib/dynamoid/application_time_zone.rb +1 -0
  18. data/lib/dynamoid/associations.rb +182 -19
  19. data/lib/dynamoid/associations/association.rb +4 -2
  20. data/lib/dynamoid/associations/belongs_to.rb +2 -1
  21. data/lib/dynamoid/associations/has_and_belongs_to_many.rb +2 -1
  22. data/lib/dynamoid/associations/has_many.rb +2 -1
  23. data/lib/dynamoid/associations/has_one.rb +2 -1
  24. data/lib/dynamoid/associations/many_association.rb +65 -22
  25. data/lib/dynamoid/associations/single_association.rb +28 -1
  26. data/lib/dynamoid/components.rb +1 -0
  27. data/lib/dynamoid/config.rb +3 -2
  28. data/lib/dynamoid/config/backoff_strategies/constant_backoff.rb +1 -0
  29. data/lib/dynamoid/config/backoff_strategies/exponential_backoff.rb +1 -0
  30. data/lib/dynamoid/config/options.rb +1 -0
  31. data/lib/dynamoid/criteria.rb +1 -0
  32. data/lib/dynamoid/criteria/chain.rb +353 -33
  33. data/lib/dynamoid/criteria/ignored_conditions_detector.rb +1 -0
  34. data/lib/dynamoid/criteria/key_fields_detector.rb +10 -1
  35. data/lib/dynamoid/criteria/nonexistent_fields_detector.rb +1 -0
  36. data/lib/dynamoid/criteria/overwritten_conditions_detector.rb +1 -0
  37. data/lib/dynamoid/dirty.rb +71 -16
  38. data/lib/dynamoid/document.rb +123 -42
  39. data/lib/dynamoid/dumping.rb +9 -0
  40. data/lib/dynamoid/dynamodb_time_zone.rb +1 -0
  41. data/lib/dynamoid/fields.rb +189 -16
  42. data/lib/dynamoid/finders.rb +65 -28
  43. data/lib/dynamoid/identity_map.rb +6 -0
  44. data/lib/dynamoid/indexes.rb +74 -15
  45. data/lib/dynamoid/log/formatter.rb +26 -0
  46. data/lib/dynamoid/middleware/identity_map.rb +1 -0
  47. data/lib/dynamoid/persistence.rb +452 -106
  48. data/lib/dynamoid/persistence/import.rb +1 -0
  49. data/lib/dynamoid/persistence/save.rb +1 -0
  50. data/lib/dynamoid/persistence/update_fields.rb +1 -0
  51. data/lib/dynamoid/persistence/upsert.rb +1 -0
  52. data/lib/dynamoid/primary_key_type_mapping.rb +1 -0
  53. data/lib/dynamoid/railtie.rb +1 -0
  54. data/lib/dynamoid/tasks/database.rb +1 -0
  55. data/lib/dynamoid/type_casting.rb +12 -0
  56. data/lib/dynamoid/undumping.rb +8 -0
  57. data/lib/dynamoid/validations.rb +2 -0
  58. data/lib/dynamoid/version.rb +1 -1
  59. metadata +7 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16a6980d441040611894ad405ce797b6ef655e9e2730b010d72ff3e65771129f
4
- data.tar.gz: 1ca556953abc411f0b7e2fd5e5c74518a7da4381b86449b2f49e81d9f76ee0a8
3
+ metadata.gz: 26990dd042447eeba355601d0c7eb3657bcc482e80d00c1da5602d2f82765504
4
+ data.tar.gz: 76e1778155fb8a7a1d3135d4886d9e7caf1a07b72263fc38d9162ae946d5dab1
5
5
  SHA512:
6
- metadata.gz: 71856592a8a381b27517682c6ce7bb48047de11dc2fbb17c175af629d3ec7e2b63895e9b24c943b57a93e47db0b1de390454b5a89d71899a59c9208a79e0595e
7
- data.tar.gz: 8cd759df57475c7566ef0ceae781d21eb443cb1dcd0f6da0f3eaa778fe6a3abeac8865a1198a2dbd2f435eec2cb5317b47ce5e5bd5b9dadbe7537a412053492b
6
+ metadata.gz: 2aadf93639577566ed5dd9dadff596316f3d22384f5d7dabd0e06aa49992d3a58e824a8c150002c3a39d6e42f7b2b17c4f383bda2c145f4d05e1d56bf21a5e54
7
+ data.tar.gz: 14801f95c8cd1a241d2b1522b05a1e7af307822cef50e4515502f641027ade16aaf750a099801a2f2e4e379b15a4cd96e78f84754278db37d2e6fcdaab57b242
@@ -1,18 +1,49 @@
1
1
  # HEAD
2
2
 
3
- ## Breaking
3
+ ## Features
4
+
5
+ ## Improvements
6
+
7
+ ## Fixes
8
+
9
+
10
+ ---
11
+
12
+
13
+
14
+ # 3.6.0 / 2020-07-13
15
+
4
16
 
5
17
  ## Features
6
18
 
19
+ * [#458](https://github.com/Dynamoid/dynamoid/pull/458) Added `binary` field type
20
+ * [#459](https://github.com/Dynamoid/dynamoid/pull/459) Added `log_formatter` config option and changed default logging format
21
+
7
22
  ## Improvements
8
23
 
24
+ * [#423](https://github.com/Dynamoid/dynamoid/pull/423) Added warning when generated for a field methods override existing ones
25
+ * [#429](https://github.com/Dynamoid/dynamoid/pull/429) Added `raise_error` option for `find` method
26
+ * [#440](https://github.com/Dynamoid/dynamoid/pull/440) Optimized performance of `first` method when there are only conditions on key attribute in a query (@mrkamel)
27
+ * [#445](https://github.com/Dynamoid/dynamoid/pull/445) Support `limit` parameter in `first` method (@mrkamel)
28
+ * [#450](https://github.com/Dynamoid/dynamoid/pull/450) Got rid of `null-logger` gem to make Dynamoid dependencies license suitable for commercial use (@yakjuly)
29
+ * [#454](https://github.com/Dynamoid/dynamoid/pull/454) Added block argument to `create`/`create!` methods
30
+ * [#456](https://github.com/Dynamoid/dynamoid/pull/456) Detect when `find` method requires a range key argument and raise `Dynamoid::Errors::MissingRangeKey` exception if it's missing
31
+ * YARD documentation:
32
+ * added missing documentation so now all the public methods are documented
33
+ * hid all the private methods and classes
34
+
9
35
  ## Fixes
10
36
 
37
+ * [#425](https://github.com/Dynamoid/dynamoid/pull/425) Fixed typos in the README.md file (@omarsotillo)
38
+ * [#432](https://github.com/Dynamoid/dynamoid/pull/432) Support tables that use "hash_key" as their partition key name (@remomueller)
39
+ * [#434](https://github.com/Dynamoid/dynamoid/pull/434) Support tables that have attribute with name "range_value"
40
+ * [#453](https://github.com/Dynamoid/dynamoid/pull/453) Fixed issue with using `type` attribute as a GSI hash key
41
+
11
42
  ---
12
43
 
13
44
 
14
45
 
15
- # 3.5 / 2020-04-04
46
+ # 3.5.0 / 2020-04-04
16
47
 
17
48
 
18
49
  ## Features
@@ -20,13 +51,13 @@
20
51
  * Feature: [#408](https://github.com/Dynamoid/dynamoid/pull/408) Added `ActiveSupport` load hook on `Dynamoid` load (@aaronmallen)
21
52
  * Feature: [#422](https://github.com/Dynamoid/dynamoid/pull/422) Added `.pluck` method
22
53
 
23
- Fixes:
54
+ ## Fixes:
24
55
  * Fix: [#410](https://github.com/Dynamoid/dynamoid/pull/410) Fixed creating GSI when table uses on-demand capacity provisioning (@icy-arctic-fox)
25
56
  * Fix: [#414](https://github.com/Dynamoid/dynamoid/pull/414) Fixed lazy table creation
26
57
  * Fix: [#415](https://github.com/Dynamoid/dynamoid/pull/415) Fixed RubyDoc comment (@walkersumida)
27
58
  * Fix: [#420](https://github.com/Dynamoid/dynamoid/pull/420) Fixed `#persisted?` for deleted/destroyed models
28
59
 
29
- Improvements:
60
+ ## Improvements:
30
61
  * Improvement: [#416](https://github.com/Dynamoid/dynamoid/pull/416) Improved speed of Adapter's `truncate` method. It now uses `#batch_delete_item` method (@TheSmartnik)
31
62
  * Improvement: [#421](https://github.com/Dynamoid/dynamoid/pull/421) Added `touch: false` option of the #save method
32
63
  * Improvement: [#423](https://github.com/Dynamoid/dynamoid/pull/423) Added warning when generated for a field methods override existing ones
data/README.md CHANGED
@@ -212,16 +212,17 @@ each field. Every field on the object must be included here; if you miss
212
212
  any they'll be completely bypassed during DynamoDB's initialization and
213
213
  will not appear on the model objects.
214
214
 
215
- By default, fields are assumed to be of type `:string`. Other built-in
216
- types are `:integer`, `:number`, `:set`, `:array`, `:map`, `:datetime`,
217
- `date`, `:boolean`, `:raw` and `:serialized`. `array` and `map` match
218
- List and Map DynamoDB types respectively. `raw` type means you can store
219
- Ruby Array, Hash, String and numbers. If built-in types do not suit you,
220
- you can use a custom field type represented by an arbitrary class,
221
- provided that the class supports a compatible serialization interface.
222
- The primary use case for using a custom field type is to represent your
223
- business logic with high-level types, while ensuring portability or
224
- backward-compatibility of the serialized representation.
215
+ By default, fields are assumed to be of type `string`. Other built-in
216
+ types are `integer`, `number`, `set`, `array`, `map`, `datetime`,
217
+ `date`, `boolean`, `binary`, `raw` and `serialized`. `array` and
218
+ `map` match List and Map DynamoDB types respectively. `raw` type means
219
+ you can store Ruby Array, Hash, String and numbers. If built-in types do
220
+ not suit you, you can use a custom field type represented by an
221
+ arbitrary class, provided that the class supports a compatible
222
+ serialization interface. The primary use case for using a custom field
223
+ type is to represent your business logic with high-level types, while
224
+ ensuring portability or backward-compatibility of the serialized
225
+ representation.
225
226
 
226
227
  #### Note on boolean type
227
228
 
@@ -232,7 +233,7 @@ easily achieve this with `store_as_native_boolean` field option:
232
233
 
233
234
  ```ruby
234
235
  class Document
235
- include DynamoId::Document
236
+ include Dynamoid::Document
236
237
 
237
238
  field :active, :boolean, store_as_native_boolean: false
238
239
  end
@@ -246,7 +247,7 @@ strings instead then set `store_as_string` to `true`
246
247
 
247
248
  ```ruby
248
249
  class Document
249
- include DynamoId::Document
250
+ include Dynamoid::Document
250
251
 
251
252
  field :sent_on, :date, store_as_string: true
252
253
  end
@@ -261,7 +262,7 @@ as ISO-8601 formatted strings instead then set `store_as_string` to
261
262
 
262
263
  ```ruby
263
264
  class Document
264
- include DynamoId::Document
265
+ include Dynamoid::Document
265
266
 
266
267
  field :sent_at, :datetime, store_as_string: true
267
268
  end
@@ -293,7 +294,7 @@ types.
293
294
 
294
295
  ```ruby
295
296
  class Document
296
- include DynamoId::Document
297
+ include Dynamoid::Document
297
298
 
298
299
  field :tags, :set, of: :integer
299
300
  end
@@ -305,7 +306,7 @@ elements type:
305
306
 
306
307
  ```ruby
307
308
  class Document
308
- include DynamoId::Document
309
+ include Dynamoid::Document
309
310
 
310
311
  field :values, :set, of: { serialized: { serializer: JSON } }
311
312
  field :dates, :set, of: { date: { store_as_string: true } }
@@ -329,7 +330,7 @@ natively, you should specify element type with `of` option:
329
330
 
330
331
  ```ruby
331
332
  class Document
332
- include DynamoId::Document
333
+ include Dynamoid::Document
333
334
 
334
335
  field :dates, :array, of: :date
335
336
  end
@@ -762,7 +763,7 @@ for requesting documents in batches:
762
763
 
763
764
  ```ruby
764
765
  # Do some maintenance on the entire table without flooding DynamoDB
765
- Address.all(batch_size: 100).each { |address| address.do_some_work; sleep(0.01) }
766
+ Address.batch(100).each { |address| address.do_some_work; sleep(0.01) }
766
767
  Address.record_limit(10_000).batch(100).each { … } # Batch specified as part of a chain
767
768
  ```
768
769
 
@@ -1068,7 +1069,7 @@ Listed below are all configuration options.
1068
1069
  * `models_dir` - `dynamoid:create_tables` rake task loads DynamoDb
1069
1070
  models from this directory. Default is `./app/models`.
1070
1071
  * `application_timezone` - Dynamoid converts all `datetime` fields to
1071
- * specified time zone when loads data from the storage.
1072
+ specified time zone when loads data from the storage.
1072
1073
  Acceptable values - `:utc`, `:local` (to use system time zone) and
1073
1074
  time zone name e.g. `Eastern Time (US & Canada)`. Default is `utc`
1074
1075
  * `dynamodb_timezone` - When a datetime field is stored in string format
@@ -1088,6 +1089,11 @@ Listed below are all configuration options.
1088
1089
  `nil`
1089
1090
  * `backoff_strategies`: is a hash and contains all available strategies.
1090
1091
  Default is { constant: ..., exponential: ...}
1092
+ * `log_formatter`: overrides default AWS SDK formatter. There are
1093
+ several canned formatters: `Aws::Log::Formatter.default`,
1094
+ `Aws::Log::Formatter.colored` and `Aws::Log::Formatter.short`. Please
1095
+ look into `Aws::Log::Formatter` AWS SDK documentation in order to
1096
+ provide own formatter.
1091
1097
  * `http_continue_timeout`: The number of seconds to wait for a
1092
1098
  100-continue HTTP response before sending the request body. Default
1093
1099
  option value is `nil`. If not specified effected value is `1`
@@ -57,6 +57,7 @@ module Dynamoid
57
57
  @included_models ||= []
58
58
  end
59
59
 
60
+ # @private
60
61
  def adapter
61
62
  @adapter ||= Adapter.new
62
63
  end
@@ -11,6 +11,7 @@ module Dynamoid
11
11
  # 1) For the rest of Dynamoid, the gateway to DynamoDB.
12
12
  # 2) Allows switching `config.adapter` to ease development of a new adapter.
13
13
  # 3) Caches the list of tables Dynamoid knows about.
14
+ # @private
14
15
  class Adapter
15
16
  def initialize
16
17
  @adapter_ = Concurrent::Atom.new(nil)
@@ -78,8 +79,8 @@ module Dynamoid
78
79
  #
79
80
  # @param [String] table the name of the table to write the object to
80
81
  # @param [Array] ids to fetch, can also be a string of just one id
81
- # @param [Hash] options: Passed to the underlying query. The :range_key option is required whenever the table has a range key,
82
- # unless multiple ids are passed in.
82
+ # @param [Hash] options Passed to the underlying query. The :range_key option is required whenever the table has a range key,
83
+ # unless multiple ids are passed in.
83
84
  #
84
85
  # @since 0.2.0
85
86
  def read(table, ids, options = {}, &blk)
@@ -94,7 +95,9 @@ module Dynamoid
94
95
  #
95
96
  # @param [String] table the name of the table to write the object to
96
97
  # @param [Array] ids to delete, can also be a string of just one id
97
- # @param [Hash] range_key of the record to delete, can also be a string of just one range_key
98
+ # @param [Hash] options allowed only +range_key+ - range key or array of
99
+ # range keys of the record to delete, can also be
100
+ # a string of just one range_key, and +conditions+
98
101
  #
99
102
  def delete(table, ids, options = {})
100
103
  range_key = options[:range_key] # array of range keys that matches the ids passed in
@@ -115,7 +118,7 @@ module Dynamoid
115
118
  # Scans a table. Generally quite slow; try to avoid using scan if at all possible.
116
119
  #
117
120
  # @param [String] table the name of the table to write the object to
118
- # @param [Hash] scan_hash a hash of attributes: matching records will be returned by the scan
121
+ # @param [Hash] query a hash of attributes: matching records will be returned by the scan
119
122
  #
120
123
  # @since 0.2.0
121
124
  def scan(table, query = {}, opts = {})
@@ -9,6 +9,7 @@ require_relative 'aws_sdk_v3/table'
9
9
  require_relative 'aws_sdk_v3/until_past_table_status'
10
10
 
11
11
  module Dynamoid
12
+ # @private
12
13
  module AdapterPlugin
13
14
  # The AwsSdkV3 adapter provides support for the aws-sdk version 2 for ruby.
14
15
  class AwsSdkV3
@@ -64,8 +65,8 @@ module Dynamoid
64
65
  # Build an array of values for Condition
65
66
  # Is used in ScanFilter and QueryFilter
66
67
  # https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Condition.html
67
- # @params [String] operator: value of RANGE_MAP or FIELD_MAP hash, e.g. "EQ", "LT" etc
68
- # @params [Object] value: scalar value or array/set
68
+ # @param [String] operator value of RANGE_MAP or FIELD_MAP hash, e.g. "EQ", "LT" etc
69
+ # @param [Object] value scalar value or array/set
69
70
  def self.attribute_value_list(operator, value)
70
71
  # For BETWEEN and IN operators we should keep value as is (it should be already an array)
71
72
  # NULL and NOT_NULL require absence of attribute list
@@ -108,12 +109,14 @@ module Dynamoid
108
109
  end
109
110
  end
110
111
 
111
- # https://github.com/aws/aws-sdk-ruby/blob/master/gems/aws-sdk-core/lib/aws-sdk-core/plugins/logging.rb
112
- # https://github.com/aws/aws-sdk-ruby/blob/master/gems/aws-sdk-core/lib/aws-sdk-core/log/formatter.rb
113
- formatter = Aws::Log::Formatter.new(':operation | Request :http_request_body | Response :http_response_body')
114
112
  @connection_hash[:logger] = Dynamoid::Config.logger
115
113
  @connection_hash[:log_level] = :debug
116
- @connection_hash[:log_formatter] = formatter
114
+
115
+ # https://github.com/aws/aws-sdk-ruby/blob/master/gems/aws-sdk-core/lib/aws-sdk-core/plugins/logging.rb
116
+ # https://github.com/aws/aws-sdk-ruby/blob/master/gems/aws-sdk-core/lib/aws-sdk-core/log/formatter.rb
117
+ if Dynamoid::Config.log_formatter
118
+ @connection_hash[:log_formatter] = Dynamoid::Config.log_formatter
119
+ end
117
120
 
118
121
  @connection_hash
119
122
  end
@@ -141,9 +144,9 @@ module Dynamoid
141
144
  # end
142
145
  #
143
146
  # @param [String] table_name the name of the table
144
- # @param [Array] items to be processed
145
- # @param [Hash] additional options
146
- # @param [Proc] optional block
147
+ # @param [Array] objects to be processed
148
+ # @param [Hash] options additional options
149
+ # @yield [true|false] invokes an optional block with argument - whether there are unprocessed items
147
150
  #
148
151
  # See:
149
152
  # * http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchWriteItem.html
@@ -198,9 +201,9 @@ module Dynamoid
198
201
  # end
199
202
  # end
200
203
  #
201
- # @param [Hash] table_ids the hash of tables and IDs to retrieve
204
+ # @param [Hash] table_names_with_ids the hash of tables and IDs to retrieve
202
205
  # @param [Hash] options to be passed to underlying BatchGet call
203
- # @param [Proc] optional block can be passed to handle each batch of items
206
+ # @param [Proc] block optional block can be passed to handle each batch of items
204
207
  #
205
208
  # @return [Hash] a hash where keys are the table names and the values are the retrieved items
206
209
  #
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dynamoid
4
+ # @private
4
5
  module AdapterPlugin
5
6
  class AwsSdkV3
6
7
  # Documentation
@@ -3,6 +3,7 @@
3
3
  require_relative 'until_past_table_status'
4
4
 
5
5
  module Dynamoid
6
+ # @private
6
7
  module AdapterPlugin
7
8
  class AwsSdkV3
8
9
  class CreateTable
@@ -87,9 +88,9 @@ module Dynamoid
87
88
  # Builds aws attributes definitions based off of primary hash/range and
88
89
  # secondary indexes
89
90
  #
90
- # @param key_data
91
- # @option key_data [Hash] hash_key_schema - eg: {:id => :string}
92
- # @option key_data [Hash] range_key_schema - eg: {:created_at => :number}
91
+ # @param key_schema
92
+ # @option key_schema [Hash] hash_key_schema - eg: {:id => :string}
93
+ # @option key_schema [Hash] range_key_schema - eg: {:created_at => :number}
93
94
  # @param [Hash] secondary_indexes
94
95
  # @option secondary_indexes [Array<Dynamoid::Indexes::Index>] :local_secondary_indexes
95
96
  # @option secondary_indexes [Array<Dynamoid::Indexes::Index>] :global_secondary_indexes
@@ -130,8 +131,8 @@ module Dynamoid
130
131
  end
131
132
 
132
133
  # Builds an attribute definitions based on hash key and range key
133
- # @params [Hash] hash_key_schema - eg: {:id => :string}
134
- # @params [Hash] range_key_schema - eg: {:created_at => :datetime}
134
+ # @param [Hash] hash_key_schema - eg: {:id => :string}
135
+ # @param [Hash] range_key_schema - eg: {:created_at => :datetime}
135
136
  # @return [Array]
136
137
  def build_attribute_definitions(hash_key_schema, range_key_schema = nil)
137
138
  attrs = []
@@ -152,8 +153,8 @@ module Dynamoid
152
153
  end
153
154
 
154
155
  # Builds an aws attribute definition based on name and dynamoid type
155
- # @params [Symbol] name - eg: :id
156
- # @params [Symbol] dynamoid_type - eg: :string
156
+ # @param [Symbol] name - eg: :id
157
+ # @param [Symbol] dynamoid_type - eg: :string
157
158
  # @return [Hash]
158
159
  def attribute_definition_element(name, dynamoid_type)
159
160
  aws_type = api_type(dynamoid_type)
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dynamoid
4
+ # @private
4
5
  module AdapterPlugin
5
6
  class AwsSdkV3
6
7
  # Mimics behavior of the yielded object on DynamoDB's update_item API (high level).
@@ -20,8 +21,8 @@ module Dynamoid
20
21
  # Adds the given values to the values already stored in the corresponding columns.
21
22
  # The column must contain a Set or a number.
22
23
  #
23
- # @param [Hash] vals keys of the hash are the columns to update, vals are the values to
24
- # add. values must be a Set, Array, or Numeric
24
+ # @param [Hash] values keys of the hash are the columns to update, values
25
+ # are the values to add. values must be a Set, Array, or Numeric
25
26
  #
26
27
  def add(values)
27
28
  @additions.merge!(sanitize_attributes(values))
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dynamoid
4
+ # @private
4
5
  module AdapterPlugin
5
6
  class AwsSdkV3
6
7
  module Middleware
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dynamoid
4
+ # @private
4
5
  module AdapterPlugin
5
6
  class AwsSdkV3
6
7
  module Middleware
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dynamoid
4
+ # @private
4
5
  module AdapterPlugin
5
6
  class AwsSdkV3
6
7
  module Middleware
@@ -5,6 +5,7 @@ require_relative 'middleware/limit'
5
5
  require_relative 'middleware/start_key'
6
6
 
7
7
  module Dynamoid
8
+ # @private
8
9
  module AdapterPlugin
9
10
  class AwsSdkV3
10
11
  class Query
@@ -5,6 +5,7 @@ require_relative 'middleware/limit'
5
5
  require_relative 'middleware/start_key'
6
6
 
7
7
  module Dynamoid
8
+ # @private
8
9
  module AdapterPlugin
9
10
  class AwsSdkV3
10
11
  class Scan
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dynamoid
4
+ # @private
4
5
  module AdapterPlugin
5
6
  class AwsSdkV3
6
7
  # Represents a table. Exposes data from the "DescribeTable" API call, and also
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dynamoid
4
+ # @private
4
5
  module AdapterPlugin
5
6
  class AwsSdkV3
6
7
  class UntilPastTableStatus
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dynamoid
4
+ # @private
4
5
  module ApplicationTimeZone
5
6
  def self.at(value)
6
7
  case Dynamoid::Config.application_timezone
@@ -25,12 +25,55 @@ module Dynamoid
25
25
  end
26
26
 
27
27
  module ClassMethods
28
- # create a has_many association for this document.
28
+ # Declare a +has_many+ association for this document.
29
29
  #
30
- # @param [Symbol] name the name of the association
31
- # @param [Hash] options options to pass to the association constructor
30
+ # class Category
31
+ # include Dynamoid::Document
32
+ #
33
+ # has_many :posts
34
+ # end
35
+ #
36
+ # Association is an enumerable collection and supports following addition
37
+ # operations:
38
+ #
39
+ # * +create+
40
+ # * +create!+
41
+ # * +destroy_all+
42
+ # * +delete_all+
43
+ # * +delete+
44
+ # * +<<+
45
+ # * +where+
46
+ # * +all+
47
+ # * +empty?+
48
+ # * +size+
49
+ #
50
+ # When a name of an associated class doesn't match an association name a
51
+ # class name should be specified explicitly either with +class+ or
52
+ # +class_name+ option:
53
+ #
54
+ # has_many :labels, class: Tag
55
+ # has_many :labels, class_name: 'Tag'
56
+ #
57
+ # When associated class has own +belongs_to+ association to
58
+ # the current class and the name doesn't match a name of the current
59
+ # class this name can be specified with +inverse_of+ option:
60
+ #
61
+ # class Post
62
+ # include Dynamoid::Document
63
+ #
64
+ # belongs_to :item, class_name: 'Tag'
65
+ # end
66
+ #
67
+ # class Tag
68
+ # include Dynamoid::Document
69
+ #
70
+ # has_many :posts, inverse_of: :item
71
+ # end
72
+ #
73
+ # @param name [Symbol] the name of the association
74
+ # @param options [Hash] options to pass to the association constructor
32
75
  # @option options [Class] :class the target class of the has_many association; that is, the belongs_to class
33
- # @option options [Symbol] :class_name the name of the target class of the association; that is, the name of the belongs_to class
76
+ # @option options [String] :class_name the name of the target class of the association; that is, the name of the belongs_to class
34
77
  # @option options [Symbol] :inverse_of the name of the association on the target class; that is, if the class has a belongs_to association, the name of that association
35
78
  #
36
79
  # @since 0.2.0
@@ -38,12 +81,47 @@ module Dynamoid
38
81
  association(:has_many, name, options)
39
82
  end
40
83
 
41
- # create a has_one association for this document.
84
+ # Declare a +has_one+ association for this document.
85
+ #
86
+ # class Image
87
+ # include Dynamoid::Document
42
88
  #
43
- # @param [Symbol] name the name of the association
44
- # @param [Hash] options options to pass to the association constructor
89
+ # has_one :post
90
+ # end
91
+ #
92
+ # Association supports following operations:
93
+ #
94
+ # * +create+
95
+ # * +create!+
96
+ # * +delete+
97
+ #
98
+ # When a name of an associated class doesn't match an association name a
99
+ # class name should be specified explicitly either with +class+ or
100
+ # +class_name+ option:
101
+ #
102
+ # has_one :item, class: Post
103
+ # has_one :item, class_name: 'Post'
104
+ #
105
+ # When associated class has own +belong_to+ association to the current
106
+ # class and the name doesn't match a name of the current class this name
107
+ # can be specified with +inverse_of+ option:
108
+ #
109
+ # class Post
110
+ # include Dynamoid::Document
111
+ #
112
+ # belongs_to :logo, class_name: 'Image'
113
+ # end
114
+ #
115
+ # class Image
116
+ # include Dynamoid::Document
117
+ #
118
+ # has_one :post, inverse_of: :logo
119
+ # end
120
+ #
121
+ # @param name [Symbol] the name of the association
122
+ # @param options [Hash] options to pass to the association constructor
45
123
  # @option options [Class] :class the target class of the has_one association; that is, the belongs_to class
46
- # @option options [Symbol] :class_name the name of the target class of the association; that is, the name of the belongs_to class
124
+ # @option options [String] :class_name the name of the target class of the association; that is, the name of the belongs_to class
47
125
  # @option options [Symbol] :inverse_of the name of the association on the target class; that is, if the class has a belongs_to association, the name of that association
48
126
  #
49
127
  # @since 0.2.0
@@ -51,25 +129,110 @@ module Dynamoid
51
129
  association(:has_one, name, options)
52
130
  end
53
131
 
54
- # create a belongs_to association for this document.
132
+ # Declare a +belongs_to+ association for this document.
133
+ #
134
+ # class Post
135
+ # include Dynamoid::Document
55
136
  #
56
- # @param [Symbol] name the name of the association
57
- # @param [Hash] options options to pass to the association constructor
137
+ # belongs_to :categories
138
+ # end
139
+ #
140
+ # Association supports following operations:
141
+ #
142
+ # * +create+
143
+ # * +create!+
144
+ # * +delete+
145
+ #
146
+ # When a name of an associated class doesn't match an association name a
147
+ # class name should be specified explicitly either with +class+ or
148
+ # +class_name+ option:
149
+ #
150
+ # belongs_to :item, class: Post
151
+ # belongs_to :item, class_name: 'Post'
152
+ #
153
+ # When associated class has own +has_many+ or +has_one+ association to
154
+ # the current class and the name doesn't match a name of the current
155
+ # class this name can be specified with +inverse_of+ option:
156
+ #
157
+ # class Category
158
+ # include Dynamoid::Document
159
+ #
160
+ # has_many :items, class_name: 'Post'
161
+ # end
162
+ #
163
+ # class Post
164
+ # include Dynamoid::Document
165
+ #
166
+ # belongs_to :categories, inverse_of: :items
167
+ # end
168
+ #
169
+ # By default a hash key attribute name is +id+. If an associated class
170
+ # uses another name for a hash key attribute it should be specified in
171
+ # the +belongs_to+ association:
172
+ #
173
+ # belongs_to :categories, foreign_key: :uuid
174
+ #
175
+ # @param name [Symbol] the name of the association
176
+ # @param options [Hash] options to pass to the association constructor
58
177
  # @option options [Class] :class the target class of the has_one association; that is, the has_many or has_one class
59
- # @option options [Symbol] :class_name the name of the target class of the association; that is, the name of the has_many or has_one class
178
+ # @option options [String] :class_name the name of the target class of the association; that is, the name of the has_many or has_one class
60
179
  # @option options [Symbol] :inverse_of the name of the association on the target class; that is, if the class has a has_many or has_one association, the name of that association
180
+ # @option options [Symbol] :foreign_key the name of a hash key attribute in the target class
61
181
  #
62
182
  # @since 0.2.0
63
183
  def belongs_to(name, options = {})
64
184
  association(:belongs_to, name, options)
65
185
  end
66
186
 
67
- # create a has_and_belongs_to_many association for this document.
187
+ # Declare a +has_and_belongs_to_many+ association for this document.
188
+ #
189
+ # class Post
190
+ # include Dynamoid::Document
191
+ #
192
+ # has_and_belongs_to_many :tags
193
+ # end
194
+ #
195
+ # Association is an enumerable collection and supports following addition
196
+ # operations:
197
+ #
198
+ # * +create+
199
+ # * +create!+
200
+ # * +destroy_all+
201
+ # * +delete_all+
202
+ # * +delete+
203
+ # * +<<+
204
+ # * +where+
205
+ # * +all+
206
+ # * +empty?+
207
+ # * +size+
208
+ #
209
+ # When a name of an associated class doesn't match an association name a
210
+ # class name should be specified explicitly either with +class+ or
211
+ # +class_name+ option:
212
+ #
213
+ # has_and_belongs_to_many :labels, class: Tag
214
+ # has_and_belongs_to_many :labels, class_name: 'Tag'
215
+ #
216
+ # When associated class has own +has_and_belongs_to_many+ association to
217
+ # the current class and the name doesn't match a name of the current
218
+ # class this name can be specified with +inverse_of+ option:
219
+ #
220
+ # class Tag
221
+ # include Dynamoid::Document
222
+ #
223
+ # has_and_belongs_to_many :items, class_name: 'Post'
224
+ # end
225
+ #
226
+ # class Post
227
+ # include Dynamoid::Document
228
+ #
229
+ # has_and_belongs_to_many :tags, inverse_of: :items
230
+ # end
68
231
  #
69
- # @param [Symbol] name the name of the association
70
- # @param [Hash] options options to pass to the association constructor
232
+ # @param name [Symbol] the name of the association
233
+ # @param options [Hash] options to pass to the association constructor
71
234
  # @option options [Class] :class the target class of the has_and_belongs_to_many association; that is, the belongs_to class
72
- # @option options [Symbol] :class_name the name of the target class of the association; that is, the name of the belongs_to class
235
+ # @option options [String] :class_name the name of the target class of the association; that is, the name of the belongs_to class
73
236
  # @option options [Symbol] :inverse_of the name of the association on the target class; that is, if the class has a belongs_to association, the name of that association
74
237
  #
75
238
  # @since 0.2.0
@@ -81,9 +244,9 @@ module Dynamoid
81
244
 
82
245
  # create getters and setters for an association.
83
246
  #
84
- # @param [Symbol] symbol the type (:has_one, :has_many, :has_and_belongs_to_many, :belongs_to) of the association
85
- # @param [Symbol] name the name of the association
86
- # @param [Hash] options options to pass to the association constructor; see above for all valid options
247
+ # @param type [Symbol] the type (:has_one, :has_many, :has_and_belongs_to_many, :belongs_to) of the association
248
+ # @param name [Symbol] the name of the association
249
+ # @param options [Hash] options to pass to the association constructor; see above for all valid options
87
250
  #
88
251
  # @since 0.2.0
89
252
  def association(type, name, options = {})