diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 8930b3d9..582393e1 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -19,6 +19,7 @@ concurrency: cancel-in-progress: false jobs: + # Generate Guides build-guides: runs-on: ubuntu-latest env: @@ -36,27 +37,55 @@ jobs: uses: actions/configure-pages@v5 - name: Build with mdBook - run: ./mdbook build + run: ./mdbook build # generates ./book directory - - name: Move into a dedicated subdirectory - run: | - mkdir -p combined-docs/guides - cp -r book/* combined-docs/guides + - name: Upload Guides Raw Material + uses: actions/upload-artifact@v4 + with: + name: guides-output + path: book - - name: Upload static files as artifact - id: deployment - uses: actions/upload-pages-artifact@v3 + # Generate API References + build-reference: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build API Reference + run: yardoc # generates ./yardoc directory + - name: Upload Guides Raw Material + uses: actions/upload-artifact@v4 with: - path: combined-docs + name: reference-output + path: yardoc - # Deployment job + # Merge and Deploy to GitHub Pages deploy: + needs: [build-guides, build-api] + runs-on: ubuntu-latest environment: name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - runs-on: ubuntu-latest - needs: build-guides + url: ${{ steps:deployment.outputs.page_url }} steps: + - name: Create Unified Deployment Directory + run: mkdir -p combined-docs + + - name: Download Guides + uses: actions/download-artifact@v4 + with: + name: guides-output + path: combined-docs/guides + + - name: Download API Reference + uses: actions/download-artifact@v4 + with: + name: reference-output + path: combined-docs/reference + + - name: Upload Single Pages Artifact + uses: actions/upload-pages-artifact@v3 + with: + path: combined-docs + - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4 diff --git a/.gitignore b/.gitignore index b198398d..f04cbaed 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ rdoc # yardoc generated .yardoc /_yardoc/ +yardoc # mdbook generated book diff --git a/.yardopts b/.yardopts index 22ce944f..50147e35 100644 --- a/.yardopts +++ b/.yardopts @@ -1 +1,2 @@ --no-private +--output-dir yardoc diff --git a/Gemfile.lock b/Gemfile.lock index 13df5b15..91ed5d63 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -172,7 +172,7 @@ GEM unicode-emoji (~> 4.1) unicode-emoji (4.2.0) uri (1.1.1) - yard (0.9.38) + yard (0.9.44) PLATFORMS ruby diff --git a/Rakefile b/Rakefile index 18be8c98..2c480806 100644 --- a/Rakefile +++ b/Rakefile @@ -48,21 +48,4 @@ YARD::Rake::YardocTask.new do |t| t.options = ['-m', 'markdown'] # optional end -desc 'Publish documentation to gh-pages' # TODO: update and use directory other than doc/ -task :publish do - Rake::Task['yard'].invoke - `git add .` - `git commit -m 'Regenerated documentation'` - `git checkout gh-pages` - `git clean -fdx` - `git checkout master -- doc` - `cp -R doc/* .` - `git rm -rf doc/` - `git add .` - `git commit -m 'Regenerated documentation'` - `git pull` - `git push` - `git checkout master` -end - task default: %i[test rubocop] diff --git a/lib/dynamoid/associations.rb b/lib/dynamoid/associations.rb index 8491c22f..9218aec8 100644 --- a/lib/dynamoid/associations.rb +++ b/lib/dynamoid/associations.rb @@ -27,11 +27,13 @@ module Associations module ClassMethods # Declare a +has_many+ association for this document. # - # class Category - # include Dynamoid::Document + # ``` + # class Category + # include Dynamoid::Document # - # has_many :posts - # end + # has_many :posts + # end + # ``` # # Association is an enumerable collection and supports following addition # operations: @@ -58,17 +60,19 @@ module ClassMethods # the current class and the name doesn't match a name of the current # class this name can be specified with +inverse_of+ option: # - # class Post - # include Dynamoid::Document + # ``` + # class Post + # include Dynamoid::Document # - # belongs_to :item, class_name: 'Tag' - # end + # belongs_to :item, class_name: 'Tag' + # end # - # class Tag - # include Dynamoid::Document + # class Tag + # include Dynamoid::Document # - # has_many :posts, inverse_of: :item - # end + # has_many :posts, inverse_of: :item + # end + # ``` # # @param name [Symbol] the name of the association # @param options [Hash] options to pass to the association constructor @@ -83,11 +87,13 @@ def has_many(name, options = {}) # Declare a +has_one+ association for this document. # - # class Image - # include Dynamoid::Document + # ``` + # class Image + # include Dynamoid::Document # - # has_one :post - # end + # has_one :post + # end + # ``` # # Association supports following operations: # @@ -106,17 +112,19 @@ def has_many(name, options = {}) # class and the name doesn't match a name of the current class this name # can be specified with +inverse_of+ option: # - # class Post - # include Dynamoid::Document + # ``` + # class Post + # include Dynamoid::Document # - # belongs_to :logo, class_name: 'Image' - # end + # belongs_to :logo, class_name: 'Image' + # end # - # class Image - # include Dynamoid::Document + # class Image + # include Dynamoid::Document # - # has_one :post, inverse_of: :logo - # end + # has_one :post, inverse_of: :logo + # end + # ``` # # @param name [Symbol] the name of the association # @param options [Hash] options to pass to the association constructor @@ -131,11 +139,13 @@ def has_one(name, options = {}) # Declare a +belongs_to+ association for this document. # - # class Post - # include Dynamoid::Document + # ``` + # class Post + # include Dynamoid::Document # - # belongs_to :categories - # end + # belongs_to :categories + # end + # ``` # # Association supports following operations: # @@ -154,17 +164,19 @@ def has_one(name, options = {}) # the current class and the name doesn't match a name of the current # class this name can be specified with +inverse_of+ option: # - # class Category - # include Dynamoid::Document + # ``` + # class Category + # include Dynamoid::Document # - # has_many :items, class_name: 'Post' - # end + # has_many :items, class_name: 'Post' + # end # - # class Post - # include Dynamoid::Document + # class Post + # include Dynamoid::Document # - # belongs_to :categories, inverse_of: :items - # end + # belongs_to :categories, inverse_of: :items + # end + # ``` # # By default a hash key attribute name is +id+. If an associated class # uses another name for a hash key attribute it should be specified in @@ -186,11 +198,13 @@ def belongs_to(name, options = {}) # Declare a +has_and_belongs_to_many+ association for this document. # - # class Post - # include Dynamoid::Document + # ``` + # class Post + # include Dynamoid::Document # - # has_and_belongs_to_many :tags - # end + # has_and_belongs_to_many :tags + # end + # ``` # # Association is an enumerable collection and supports following addition # operations: @@ -217,17 +231,19 @@ def belongs_to(name, options = {}) # the current class and the name doesn't match a name of the current # class this name can be specified with +inverse_of+ option: # - # class Tag - # include Dynamoid::Document + # ``` + # class Tag + # include Dynamoid::Document # - # has_and_belongs_to_many :items, class_name: 'Post' - # end + # has_and_belongs_to_many :items, class_name: 'Post' + # end # - # class Post - # include Dynamoid::Document + # class Post + # include Dynamoid::Document # - # has_and_belongs_to_many :tags, inverse_of: :items - # end + # has_and_belongs_to_many :tags, inverse_of: :items + # end + # ``` # # @param name [Symbol] the name of the association # @param options [Hash] options to pass to the association constructor diff --git a/lib/dynamoid/associations/association.rb b/lib/dynamoid/associations/association.rb index 19f627a3..f719f531 100644 --- a/lib/dynamoid/associations/association.rb +++ b/lib/dynamoid/associations/association.rb @@ -6,9 +6,10 @@ module Dynamoid # The target is the object which is referencing by this association. # @private module Associations - # @private module Association - attr_accessor :name, :options, :source, :loaded + attr_accessor :name, :options, :source + # @private + attr_accessor :loaded # Create a new association. # @@ -30,12 +31,15 @@ def initialize(source, name, options) @loaded = false end + # @private def loaded? @loaded end + # @private def find_target; end + # @private def target unless loaded? @target = find_target @@ -45,19 +49,23 @@ def target @target end + # @private def reset @target = nil @loaded = false end + # @private def declaration_field_name "#{name}_ids" end + # @private def declaration_field_type :set end + # @private def disassociate_source Array(target).each do |target_entry| target_entry.send(target_association).disassociate(source.hash_key) if target_entry && target_association diff --git a/lib/dynamoid/associations/belongs_to.rb b/lib/dynamoid/associations/belongs_to.rb index 52c45556..1d5a25dd 100644 --- a/lib/dynamoid/associations/belongs_to.rb +++ b/lib/dynamoid/associations/belongs_to.rb @@ -4,14 +4,15 @@ module Dynamoid # The belongs_to association. For belongs_to, we reference only a single target instead of multiple records; that target is the # object to which the association object is associated. module Associations - # @private class BelongsTo include SingleAssociation + # @private def declaration_field_name options[:foreign_key] || "#{name}_ids" end + # @private def declaration_field_type if options[:foreign_key] target_class.attributes[target_class.hash_key][:type] @@ -20,6 +21,7 @@ def declaration_field_type end end + # @private # Override default implementation # to handle case when we store id as scalar value, not as collection def associate(hash_key) diff --git a/lib/dynamoid/associations/has_and_belongs_to_many.rb b/lib/dynamoid/associations/has_and_belongs_to_many.rb index ce57b0e8..409ffbd2 100644 --- a/lib/dynamoid/associations/has_and_belongs_to_many.rb +++ b/lib/dynamoid/associations/has_and_belongs_to_many.rb @@ -3,7 +3,6 @@ module Dynamoid # The has and belongs to many association. module Associations - # @private class HasAndBelongsToMany include ManyAssociation diff --git a/lib/dynamoid/associations/has_many.rb b/lib/dynamoid/associations/has_many.rb index b5068c1e..ce4c897a 100644 --- a/lib/dynamoid/associations/has_many.rb +++ b/lib/dynamoid/associations/has_many.rb @@ -3,7 +3,6 @@ module Dynamoid # The has_many association. module Associations - # @private class HasMany include ManyAssociation diff --git a/lib/dynamoid/associations/has_one.rb b/lib/dynamoid/associations/has_one.rb index 18c38e82..7cdc2b75 100644 --- a/lib/dynamoid/associations/has_one.rb +++ b/lib/dynamoid/associations/has_one.rb @@ -1,9 +1,8 @@ # frozen_string_literal: true module Dynamoid - # The HasOne association. module Associations - # @private + # The HasOne association. class HasOne include Association include SingleAssociation diff --git a/lib/dynamoid/associations/many_association.rb b/lib/dynamoid/associations/many_association.rb index 407ec32e..24724e90 100644 --- a/lib/dynamoid/associations/many_association.rb +++ b/lib/dynamoid/associations/many_association.rb @@ -5,6 +5,7 @@ module Associations module ManyAssociation include Association + # @private attr_accessor :query def initialize(*args) diff --git a/lib/dynamoid/criteria/chain.rb b/lib/dynamoid/criteria/chain.rb index 3dfd3b1b..8fec9bb9 100644 --- a/lib/dynamoid/criteria/chain.rb +++ b/lib/dynamoid/criteria/chain.rb @@ -9,10 +9,12 @@ module Criteria # The criteria chain is equivalent to an ActiveRecord relation (and realistically I should change the name from # chain to relation). It is a chainable object that builds up a query and eventually executes it by a Query or Scan. class Chain + # @private attr_reader :source, :consistent_read, :key_fields_detector include Enumerable + # @private ALLOWED_FIELD_OPERATORS = Set.new( %w[ eq ne gt lt gte lte between begins_with in contains not_contains null not_null @@ -303,9 +305,11 @@ def scan_limit(limit) # the specified size instead of relying on the default paging mechanism # of DynamoDB. # - # Post.where(links_count: 2).batch(1000).all.each do |post| - # # process a post - # end + # ``` + # Post.where(links_count: 2).batch(1000).all.each do |post| + # # process a post + # end + # ``` # # It's useful to limit memory usage or throughput consumption # @@ -368,19 +372,20 @@ def scan_index_forward(scan_index_forward) # needs. When this case occurs you may want to force an order. This occurs # when you are searching by hash key, but not specifying a range key. # - # class Comment - # include Dynamoid::Document + # ``` + # class Comment + # include Dynamoid::Document # - # table key: :post_id - # range_key :author_id + # table key: :post_id + # range_key :author_id # - # field :post_date, :datetime + # field :post_date, :datetime # - # global_secondary_index name: :time_sorted_comments, hash_key: :post_id, range_key: post_date, projected_attributes: :all - # end + # global_secondary_index name: :time_sorted_comments, hash_key: :post_id, range_key: post_date, projected_attributes: :all + # end # - # - # Comment.where(post_id: id).with_index(:time_sorted_comments).scan_index_forward(false) + # Comment.where(post_id: id).with_index(:time_sorted_comments).scan_index_forward(false) + # ``` # # @return [Dynamoid::Criteria::Chain] def with_index(index_name) @@ -394,14 +399,16 @@ def with_index(index_name) # Allows to use the results of a search as an enumerable over the results # found. # - # Post.each do |post| - # end + # ``` + # Post.each do |post| + # end # - # Post.all.each do |post| - # end + # Post.all.each do |post| + # end # - # Post.where(links_count: 2).each do |post| - # end + # Post.where(links_count: 2).each do |post| + # end + # ``` # # It works similar to the +all+ method so results are loaded lazily. # @@ -418,9 +425,11 @@ def each(&block) # # The pages are loaded lazily. # - # Post.where('views_count.gt' => 1000).find_by_pages do |posts, options| - # # process posts - # end + # ``` + # Post.where('views_count.gt' => 1000).find_by_pages do |posts, options| + # # process posts + # end + # ``` # # It passes as block argument an +Array+ of models and a Hash with options. # @@ -428,21 +437,25 @@ def each(&block) # evaluated key is a Hash with key attributes of the last item processed by # DynamoDB. It can be used to resume querying using the +start+ method. # - # posts, options = Post.where('views_count.gt' => 1000).find_by_pages.first - # last_key = options[:last_evaluated_key] + # ``` + # posts, options = Post.where('views_count.gt' => 1000).find_by_pages.first + # last_key = options[:last_evaluated_key] # - # # ... + # # ... # - # Post.where('views_count.gt' => 1000).start(last_key).find_by_pages do |posts, options| - # end + # Post.where('views_count.gt' => 1000).start(last_key).find_by_pages do |posts, options| + # end + # ``` # # If it's called without a block then it returns an +Enumerator+. # - # enum = Post.where('views_count.gt' => 1000).find_by_pages + # ``` + # enum = Post.where('views_count.gt' => 1000).find_by_pages # - # enum.each do |posts, options| - # # process posts - # end + # enum.each do |posts, options| + # # process posts + # end + # ``` # # @return [Enumerator::Lazy] def find_by_pages(&block) diff --git a/lib/dynamoid/dirty.rb b/lib/dynamoid/dirty.rb index 1755fd6e..aaee75dc 100644 --- a/lib/dynamoid/dirty.rb +++ b/lib/dynamoid/dirty.rb @@ -154,7 +154,7 @@ def changes_applied # Remove changes information for the provided attributes. # - # @param attributes [Array[String]] - a list of attributes to clear changes for + # @param names [Array[String]] - a list of attributes to clear changes for def clear_attribute_changes(names) attributes_changed_by_setter.except!(*names) @@ -195,7 +195,7 @@ def attribute_was(name) # Restore all previous data of the provided attributes. # - # @param attributes [Array[Symbol]] a list of attribute names + # @param names [Array[Symbol]] a list of attribute names def restore_attributes(names = changed) names.each { |name| restore_attribute! name } end @@ -325,6 +325,7 @@ def attribute_changed_in_place?(name) end end + # @private module DeepDupper def self.dup_attributes(attributes, klass) attributes.map do |name, value| diff --git a/lib/dynamoid/document.rb b/lib/dynamoid/document.rb index 8591e7d0..244dfd83 100644 --- a/lib/dynamoid/document.rb +++ b/lib/dynamoid/document.rb @@ -89,25 +89,29 @@ def count # # Initialize an object and pass it into a block to set other attributes. # - # User.build(name: 'A') do |u| - # u.age = 21 - # end + # ``` + # User.build(name: 'A') do |u| + # u.age = 21 + # end + # ``` # # The only difference between +build+ and +new+ methods is that +build+ # supports STI (Single table inheritance) and looks at the inheritance # field. So it can build a model of actual class. For instance: # - # class Employee - # include Dynamoid::Document + # ``` + # class Employee + # include Dynamoid::Document # - # field :type - # field :name - # end + # field :type + # field :name + # end # - # class Manager < Employee - # end + # class Manager < Employee + # end # - # Employee.build(name: 'Alice', type: 'Manager') # => # + # Employee.build(name: 'Alice', type: 'Manager') # => # + # ``` # # @param attrs [Hash] Attributes with which to create the document # @param block [Proc] Block to process a document after initialization @@ -131,13 +135,15 @@ def build(attrs = {}, &block) # # Or in case when a range key is declared: # - # User.exists?( - # [ - # ['713', 'range-key-value-1'], - # ['714', 'range-key-value-2'], - # ['715', 'range-key-value-3'] - # ] - # ) + # ``` + # User.exists?( + # [ + # ['713', 'range-key-value-1'], + # ['714', 'range-key-value-2'], + # ['715', 'range-key-value-3'] + # ] + # ) + # ``` # # It's also possible to specify models not with primary key but with # conditions on the attributes (in the +where+ method style): @@ -193,9 +199,11 @@ def choose_right_class(attrs) # # Initialize an object and pass it into a block to set other attributes. # - # User.new(name: 'A') do |u| - # u.age = 21 - # end + # ``` + # User.new(name: 'A') do |u| + # u.age = 21 + # end + # ``` # # @param attrs [Hash] Attributes with which to create the document # @param block [Proc] Block to process a document after initialization diff --git a/lib/dynamoid/fields.rb b/lib/dynamoid/fields.rb index 36113d28..3ead3579 100644 --- a/lib/dynamoid/fields.rb +++ b/lib/dynamoid/fields.rb @@ -26,13 +26,15 @@ module Fields module ClassMethods # Specify a field for a document. # - # class User - # include Dynamoid::Document + # ``` + # class User + # include Dynamoid::Document # - # field :last_name - # field :age, :integer - # field :last_sign_in, :datetime - # end + # field :last_name + # field :age, :integer + # field :last_sign_in, :datetime + # end + # ``` # # Its type determines how it is coerced when read in and out of the # data store. You can specify +string+, +integer+, +number+, +set+, +array+, @@ -101,35 +103,39 @@ module ClassMethods # # It works in the following way: # - # class User - # include Dynamoid::Document + # ``` + # class User + # include Dynamoid::Document # - # field :age, :integer - # end + # field :age, :integer + # end # - # user = User.new - # user.age # => nil - # user.age? # => false + # user = User.new + # user.age # => nil + # user.age? # => false # - # user.age = 20 - # user.age? # => true + # user.age = 20 + # user.age? # => true # - # user.age = '21' - # user.age # => 21 - integer - # user.age_before_type_cast # => '21' - string + # user.age = '21' + # user.age # => 21 - integer + # user.age_before_type_cast # => '21' - string + # ``` # # There is also an option +alias+ which allows to use another name for a # field: # - # class User - # include Dynamoid::Document + # ``` + # class User + # include Dynamoid::Document # - # field :firstName, :string, alias: :first_name - # end + # field :firstName, :string, alias: :first_name + # end # - # user = User.new(firstName: 'Michael') - # user.firstName # Michael - # user.first_name # Michael + # user = User.new(firstName: 'Michael') + # user.firstName # Michael + # user.first_name # Michael + # ``` # # @param name [Symbol] name of the field # @param type [Symbol] type of the field (optional) @@ -152,11 +158,13 @@ def field(name, type = :string, options = {}) # Declare a table range key. # - # class User - # include Dynamoid::Document + # ``` + # class User + # include Dynamoid::Document # - # range :last_name - # end + # range :last_name + # end + # ``` # # By default a range key is a string. In order to use any other type it # should be specified as a second argument: @@ -187,29 +195,35 @@ def range(name, type = :string, options = {}) # # The +table+ method can be used to override the defaults: # - # class User - # include Dynamoid::Document + # ``` + # class User + # include Dynamoid::Document # - # table name: :customers, key: :uuid - # end + # table name: :customers, key: :uuid + # end + # ``` # # The hash key field is declared by default and a type is a string. If # another type is needed the field should be declared explicitly: # - # class User - # include Dynamoid::Document + # ``` + # class User + # include Dynamoid::Document # - # field :id, :integer - # end + # field :id, :integer + # end + # ``` # # To declare a new attribute with not-default type as a table hash key a # :key_type option can be used: # - # class User - # include Dynamoid::Document + # ``` + # class User + # include Dynamoid::Document # - # table key: :user_id, key_type: :integer - # end + # table key: :user_id, key_type: :integer + # end + # ``` # # @param options [Hash] options to override default table settings # @option options [Symbol] :name name of a table diff --git a/lib/dynamoid/finders.rb b/lib/dynamoid/finders.rb index a820b77b..4aa38a39 100644 --- a/lib/dynamoid/finders.rb +++ b/lib/dynamoid/finders.rb @@ -243,7 +243,7 @@ def find_all_by_composite_key(hash_key, options = {}) # field :email, :string # field :age, :integer # field :gender, :string - # field :rank :number + # field :rank, :number # end # # # NOTE: the first param and the second param are both hashes, diff --git a/lib/dynamoid/persistence.rb b/lib/dynamoid/persistence.rb index 9f8f0d53..cf50c79d 100644 --- a/lib/dynamoid/persistence.rb +++ b/lib/dynamoid/persistence.rb @@ -48,17 +48,19 @@ def table_name # # For instance here # - # class User - # include Dynamoid::Document + # ``` + # class User + # include Dynamoid::Document # - # table key: :uuid - # range :last_name + # table key: :uuid + # range :last_name # - # field :first_name - # field :last_name - # end + # field :first_name + # field :last_name + # end # - # User.create_table + # User.create_table + # ``` # # +create_table+ method call will create a table +dynamoid_users+ with # hash key +uuid+ and range key +name+, DynamoDB default billing mode and @@ -186,9 +188,11 @@ def import(array_of_attributes) # Instantiates a model and pass it into an optional block to set other # attributes. # - # User.create(first_name: 'Mark') do |u| - # u.age = 21 - # end + # ``` + # User.create(first_name: 'Mark') do |u| + # u.age = 21 + # end + # ``` # # Validates model and runs callbacks. # @@ -227,9 +231,11 @@ def create(attrs = {}, &block) # Instantiates a model and pass it into an optional block to set other # attributes. # - # User.create!(first_name: 'Mark') do |u| - # u.age = 21 - # end + # ``` + # User.create!(first_name: 'Mark') do |u| + # u.age = 21 + # end + # ``` # # Validates model and runs callbacks. # @@ -854,23 +860,29 @@ def update_attribute!(attribute, value) # Operation +add+ just adds a value for numeric attributes and join # collections if attribute is a set. # - # user.update! do |t| - # t.add(age: 1, followers_count: 5) - # t.add(hobbies: ['skying', 'climbing']) - # end + # ``` + # user.update! do |t| + # t.add(age: 1, followers_count: 5) + # t.add(hobbies: ['skying', 'climbing']) + # end + # ``` # # Operation +delete+ is applied to collection attribute types and # substructs one collection from another. # - # user.update! do |t| - # t.delete(hobbies: ['skying']) - # end + # ``` + # user.update! do |t| + # t.delete(hobbies: ['skying']) + # end + # ``` # # Operation +set+ just changes an attribute value: # - # user.update! do |t| - # t.set(age: 21) - # end + # ``` + # user.update! do |t| + # t.set(age: 21) + # end + # ``` # # All the operations work like +ADD+, +DELETE+ and +PUT+ actions supported # by +AttributeUpdates+ @@ -883,18 +895,22 @@ def update_attribute!(attribute, value) # # Can update a model conditionaly: # - # user.update!(if: { age: 20 }) do |t| - # t.add(age: 1) - # end + # ``` + # user.update!(if: { age: 20 }) do |t| + # t.add(age: 1) + # end + # ``` # # To check if some attribute (or attributes) isn't stored in a DynamoDB # item (e.g. it wasn't set explicitly) there is another condition - # +unless_exists+: # - # user = User.create(name: 'Tylor') - # user.update!(unless_exists: [:age]) do |t| - # t.set(age: 18) - # end + # ``` + # user = User.create(name: 'Tylor') + # user.update!(unless_exists: [:age]) do |t| + # t.set(age: 18) + # end + # ``` # # If a document doesn't meet conditions it raises # +Dynamoid::Errors::StaleObjectError+ exception. @@ -961,36 +977,46 @@ def update!(conditions = {}) # Operation +add+ just adds a value for numeric attributes and join # collections if attribute is a set. # - # user.update do |t| - # t.add(age: 1, followers_count: 5) - # t.add(hobbies: ['skying', 'climbing']) - # end + # ``` + # user.update do |t| + # t.add(age: 1, followers_count: 5) + # t.add(hobbies: ['skying', 'climbing']) + # end + # ``` # # Operation +delete+ is applied to collection attribute types and # substructs one collection from another. # - # user.update do |t| - # t.delete(hobbies: ['skying']) - # end + # ``` + # user.update do |t| + # t.delete(hobbies: ['skying']) + # end + # ``` # # If it's applied to a scalar attribute then the item's attribute is # removed at all: # - # user.update do |t| - # t.delete(age: nil) - # end + # ``` + # user.update do |t| + # t.delete(age: nil) + # end + # ``` # # or even without useless value at all: # - # user.update do |t| - # t.delete(:age) - # end + # ``` + # user.update do |t| + # t.delete(:age) + # end + # ``` # # Operation +set+ just changes an attribute value: # - # user.update do |t| - # t.set(age: 21) - # end + # ``` + # user.update do |t| + # t.set(age: 21) + # end + # ``` # # All the operations works like +ADD+, +DELETE+ and +PUT+ actions supported # by +AttributeUpdates+ @@ -999,18 +1025,22 @@ def update!(conditions = {}) # # Can update a model conditionaly: # - # user.update(if: { age: 20 }) do |t| - # t.add(age: 1) - # end + # ``` + # user.update(if: { age: 20 }) do |t| + # t.add(age: 1) + # end + # ``` # # To check if some attribute (or attributes) isn't stored in a DynamoDB # item (e.g. it wasn't set explicitly) there is another condition - # +unless_exists+: # - # user = User.create(name: 'Tylor') - # user.update(unless_exists: [:age]) do |t| - # t.set(age: 18) - # end + # ``` + # user = User.create(name: 'Tylor') + # user.update(unless_exists: [:age]) do |t| + # t.set(age: 18) + # end + # ``` # # If a document doesn't meet conditions it just returns +false+. Otherwise it returns +true+. # diff --git a/lib/dynamoid/transactions/mutation.rb b/lib/dynamoid/transactions/mutation.rb index bfc189a5..d501fb02 100644 --- a/lib/dynamoid/transactions/mutation.rb +++ b/lib/dynamoid/transactions/mutation.rb @@ -21,14 +21,16 @@ module Transactions # The persistence methods are designed to mirror their non-transactional # counterparts like +.create+, +#save+, and +#delete+: # - # user = User.new(name: 'John') - # payment = Payment.find(1) + # ``` + # user = User.new(name: 'John') + # payment = Payment.find(1) # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.save! user - # t.create! Account, name: 'A' - # t.delete payment - # end + # Dynamoid::Transactions::Mutation.execute do |t| + # t.save! user + # t.create! Account, name: 'A' + # t.delete payment + # end + # ``` # # The primary difference is that these methods are called on a transaction # instance, and the model (or class) must be passed as an argument. @@ -86,12 +88,14 @@ module Transactions # Raising +Dynamoid::Errors::Rollback+ will interrupt the transaction without # propagating the exception further: # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.save! user - # t.create! Account, name: 'A' + # ``` + # Dynamoid::Transactions::Mutation.execute do |t| + # t.save! user + # t.create! Account, name: 'A' # - # raise Dynamoid::Errors::Rollback if user.is_admin? - # end + # raise Dynamoid::Errors::Rollback if user.is_admin? + # end + # ``` # # When a transaction is successfully committed or rolled back, the corresponding # +#after_commit+ or +#after_rollback+ callbacks are run for each involved model. @@ -144,9 +148,11 @@ def rollback # # Runs callbacks. # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.touch(user) - # end + # ``` + # Dynamoid::Transactions::Mutation.execute do |t| + # t.touch(user) + # end + # ``` # # If attribute names are passed, they are updated along with updated_at # attribute: @@ -172,19 +178,23 @@ def touch(model, *names, time: nil) # Run the validation and callbacks. Returns +true+ if saving is successful # and +false+ otherwise. # - # user = User.new + # ``` + # user = User.new # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.save!(user) - # end + # Dynamoid::Transactions::Mutation.execute do |t| + # t.save!(user) + # end + # ``` # # Validation can be skipped with +validate: false+ option: # - # user = User.new(age: -1) + # ``` + # user = User.new(age: -1) # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.save!(user, validate: false) - # end + # Dynamoid::Transactions::Mutation.execute do |t| + # t.save!(user, validate: false) + # end + # ``` # # +save!+ by default sets timestamps attributes - +created_at+ and # +updated_at+ when creates new model and updates +updated_at+ attribute @@ -203,7 +213,6 @@ def touch(model, *names, time: nil) # # There are the following differences between transactional and # non-transactional +#save!+: - # - transactional +#save!+ doesn't support the +:touch+ option # - transactional +#save!+ doesn't raise +Dynamoid::Errors::StaleObjectError+ # when optimistic concurrency control detects a conflict. A generic # +Aws::DynamoDB::Errors::TransactionCanceledException+ is raised instead. @@ -218,6 +227,7 @@ def touch(model, *names, time: nil) # @param model [Dynamoid::Document] a model # @param options [Hash] (optional) # @option options [true|false] :validate validate a model or not - +true+ by default (optional) + # @option options [true|false] :touch update tiemstamps fields or not - +true+ by default (optional) # @return [true|false] Whether saving successful or not def save!(model, **options) action = Save.new(model, **options, raise_error: true) @@ -229,19 +239,23 @@ def save!(model, **options) # Run the validation and callbacks. Raise # +Dynamoid::Errors::DocumentNotValid+ unless this object is valid. # - # user = User.new + # ``` + # user = User.new # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.save(user) - # end + # Dynamoid::Transactions::Mutation.execute do |t| + # t.save(user) + # end + # ``` # # Validation can be skipped with +validate: false+ option: # - # user = User.new(age: -1) + # ``` + # user = User.new(age: -1) # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.save(user, validate: false) - # end + # Dynamoid::Transactions::Mutation.execute do |t| + # t.save(user, validate: false) + # end + # ``` # # +save+ by default sets timestamps attributes - +created_at+ and # +updated_at+ when creates new model and updates +updated_at+ attribute @@ -260,7 +274,6 @@ def save!(model, **options) # # There are the following differences between transactional and # non-transactional +#save+: - # - transactional +#save+ doesn't support the +:touch+ option # - transactional +#save+ doesn't raise +Dynamoid::Errors::StaleObjectError+ # when optimistic concurrency control detects a conflict. A generic # +Aws::DynamoDB::Errors::TransactionCanceledException+ is raised instead. @@ -274,6 +287,7 @@ def save!(model, **options) # @param model [Dynamoid::Document] a model # @param options [Hash] (optional) # @option options [true|false] :validate validate a model or not - +true+ by default (optional) + # @option options [true|false] :touch update tiemstamps fields or not - +true+ by default (optional) # @return [true|false] Whether saving successful or not def save(model, **options) action = Save.new(model, **options, raise_error: false) @@ -282,24 +296,30 @@ def save(model, **options) # Create a model. # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.create!(User, name: 'A') - # end + # ``` + # Dynamoid::Transactions::Mutation.execute do |t| + # t.create!(User, name: 'A') + # end + # ``` # # Accepts both Hash and Array of Hashes and can create several models. # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.create!(User, [{name: 'A'}, {name: 'B'}, {name: 'C'}]) - # end + # ``` + # Dynamoid::Transactions::Mutation.execute do |t| + # t.create!(User, [{name: 'A'}, {name: 'B'}, {name: 'C'}]) + # end + # ``` # # Instantiates a model and pass it into an optional block to set other # attributes. # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.create!(User, name: 'A') do |user| - # user.initialize_roles - # end + # ``` + # Dynamoid::Transactions::Mutation.execute do |t| + # t.create!(User, name: 'A') do |user| + # user.initialize_roles # end + # end + # ``` # # Validates model and runs callbacks. # @@ -331,24 +351,30 @@ def create!(model_class, attributes = {}, &block) # Create a model. # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.create(User, name: 'A') - # end + # ``` + # Dynamoid::Transactions::Mutation.execute do |t| + # t.create(User, name: 'A') + # end + # ``` # # Accepts both Hash and Array of Hashes and can create several models. # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.create(User, [{name: 'A'}, {name: 'B'}, {name: 'C'}]) - # end + # ``` + # Dynamoid::Transactions::Mutation.execute do |t| + # t.create(User, [{name: 'A'}, {name: 'B'}, {name: 'C'}]) + # end + # ``` # # Instantiates a model and pass it into an optional block to set other # attributes. # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.create(User, name: 'A') do |user| - # user.initialize_roles - # end + # ``` + # Dynamoid::Transactions::Mutation.execute do |t| + # t.create(User, name: 'A') do |user| + # user.initialize_roles # end + # end + # ``` # # Validates model and runs callbacks. # @@ -384,15 +410,19 @@ def create(model_class, attributes = {}, &block) # creates a new document with specified attributes. Doesn't run # validations and callbacks. # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.upsert(User, '1', age: 26) - # end + # ``` + # Dynamoid::Transactions::Mutation.execute do |t| + # t.upsert(User, '1', age: 26) + # end + # ``` # # If range key is declared for a model it should be passed as well: # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.upsert(User, '1', 'Tylor', age: 26) - # end + # ``` + # Dynamoid::Transactions::Mutation.execute do |t| + # t.upsert(User, '1', 'Tylor', age: 26) + # end + # ``` # # Raises a +Dynamoid::Errors::UnknownAttribute+ exception if any of the # attributes is not declared in the model class. @@ -422,52 +452,66 @@ def upsert(model_class, hash_key, range_key = nil, attributes) # rubocop:disable # # Doesn't run validations and callbacks. # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.update_fields(User, '1', age: 26) - # end + # ``` + # Dynamoid::Transactions::Mutation.execute do |t| + # t.update_fields(User, '1', age: 26) + # end + # ``` # # If range key is declared for a model it should be passed as well: # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.update_fields(User, '1', 'Tylor', age: 26) - # end + # ``` + # Dynamoid::Transactions::Mutation.execute do |t| + # t.update_fields(User, '1', 'Tylor', age: 26) + # end + # ``` # # Updates can also be performed in a block. # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.update_fields(User, 1) do |u| - # u.add(article_count: 1) - # u.delete(favorite_colors: 'green') - # u.set(age: 27, last_name: 'Tylor') - # end + # ``` + # Dynamoid::Transactions::Mutation.execute do |t| + # t.update_fields(User, 1) do |u| + # u.add(article_count: 1) + # u.delete(favorite_colors: 'green') + # u.set(age: 27, last_name: 'Tylor') # end + # end + # ``` # # Operation +add+ just adds a value for numeric attributes and join # collections if attribute is a set. # - # t.update_fields(User, 1) do |u| - # u.add(age: 1, followers_count: 5) - # u.add(hobbies: ['skying', 'climbing']) - # end + # ``` + # t.update_fields(User, 1) do |u| + # u.add(age: 1, followers_count: 5) + # u.add(hobbies: ['skying', 'climbing']) + # end + # ``` # # Operation +delete+ is applied to collection attribute types and # substructs one collection from another. # - # t.update_fields(User, 1) do |u| - # u.delete(hobbies: ['skying']) - # end + # ``` + # t.update_fields(User, 1) do |u| + # u.delete(hobbies: ['skying']) + # end + # ``` # # Operation +set+ just changes an attribute value: # - # t.update_fields(User, 1) do |u| - # u.set(age: 21) - # end + # ``` + # t.update_fields(User, 1) do |u| + # u.set(age: 21) + # end + # ``` # # Operation +remove+ removes one or more attributes from an item. # - # t.update_fields(User, 1) do |u| - # u.remove(:age) - # end + # ``` + # t.update_fields(User, 1) do |u| + # u.remove(:age) + # end + # ``` # # All the operations work like +ADD+, +DELETE+, +REMOVE+, and +SET+ actions supported # by +UpdateExpression+ @@ -512,22 +556,28 @@ def update_fields(model_class, hash_key, range_key = nil, attributes = nil, &blo # # Doesn't run validations and callbacks. # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.inc(User, '1', age: 1) - # end + # ``` + # Dynamoid::Transactions::Mutation.execute do |t| + # t.inc(User, '1', age: 1) + # end + # ``` # # If range key is declared for a model it should be passed as well: # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.inc(User, '1', 'Tylor', age: 1) - # end + # ``` + # Dynamoid::Transactions::Mutation.execute do |t| + # t.inc(User, '1', 'Tylor', age: 1) + # end + # ``` # # It also supports +touch+ option to update +updated_at+ attribute and # optionally other specified attributes. # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.inc(User, '1', age: 1, touch: true) - # end + # ``` + # Dynamoid::Transactions::Mutation.execute do |t| + # t.inc(User, '1', age: 1, touch: true) + # end + # ``` # # If attribute names are passed, they are updated along with updated_at # attribute: @@ -565,10 +615,12 @@ def inc(model_class, hash_key, range_key = nil, counters = nil) # Initializes attribute to zero if +nil+ and adds the specified value (by # default is 1). Only makes sense for number-based attributes. # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.increment!(user, :followers_count) - # t.increment!(user, :followers_count, 2) - # end + # ``` + # Dynamoid::Transactions::Mutation.execute do |t| + # t.increment!(user, :followers_count) + # t.increment!(user, :followers_count, 2) + # end + # ``` # # Only `attribute` is saved. The model itself is not saved. So any other # modified attributes will still be dirty. Validations and callbacks are @@ -599,10 +651,12 @@ def increment!(model, attribute, by = 1, touch: nil) # # Runs callbacks. # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.decrement!(user, :followers_count) - # t.decrement!(user, :followers_count, 2) - # end + # ``` + # Dynamoid::Transactions::Mutation.execute do |t| + # t.decrement!(user, :followers_count) + # t.decrement!(user, :followers_count, 2) + # end + # ``` # # Only `attribute` is saved. The model itself is not saved. So any other # modified attributes will still be dirty. Validations are skipped. @@ -626,9 +680,11 @@ def decrement!(model, attribute, by = 1, touch: nil) # Update multiple attributes at once. # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.update_attributes(user, age: 27, last_name: 'Tylor') - # end + # ``` + # Dynamoid::Transactions::Mutation.execute do |t| + # t.update_attributes(user, age: 27, last_name: 'Tylor') + # end + # ``` # # Returns +true+ if saving is successful and +false+ # otherwise. @@ -662,9 +718,11 @@ def update_attributes(model, attributes) # Returns +true+ if saving is successful and +false+ # otherwise. # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.update_attributes(user, age: 27, last_name: 'Tylor') - # end + # ``` + # Dynamoid::Transactions::Mutation.execute do |t| + # t.update_attributes(user, age: 27, last_name: 'Tylor') + # end + # ``` # # Raises a +Dynamoid::Errors::DocumentNotValid+ exception if some vaidation # fails. @@ -694,9 +752,11 @@ def update_attributes!(model, attributes) # Update a single attribute, saving the object afterwards. # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.update_attribute(user, :last_name, 'Tylor') - # end + # ``` + # Dynamoid::Transactions::Mutation.execute do |t| + # t.update_attribute(user, :last_name, 'Tylor') + # end + # ``` # # Validation is skipped. # @@ -714,9 +774,11 @@ def update_attribute(model, attribute, value) # Update a single attribute, saving the object afterwards. # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.update_attribute!(user, :last_name, 'Tylor') - # end + # ``` + # Dynamoid::Transactions::Mutation.execute do |t| + # t.update_attribute!(user, :last_name, 'Tylor') + # end + # ``` # # Validation is skipped. # @@ -741,15 +803,19 @@ def update_attribute!(model, attribute, value) # # Can be called either with a model: # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.delete(user) - # end + # ``` + # Dynamoid::Transactions::Mutation.execute do |t| + # t.delete(user) + # end + # ``` # # or with a primary key: # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.delete(User, user_id) - # end + # ``` + # Dynamoid::Transactions::Mutation.execute do |t| + # t.delete(User, user_id) + # end + # ``` # # Raises +Dynamoid::Errors::MissingHashKey+ if a partition key has value # +nil+ and raises +Dynamoid::Errors::MissingRangeKey+ if a sort key is @@ -835,9 +901,11 @@ def destroy(model) # # Validations and callbacks are skipped. # - # Dynamoid::Transactions::Mutation.execute do |t| - # t.import(User, [{ name: 'A' }, { name: 'B' }]) - # end + # ``` + # Dynamoid::Transactions::Mutation.execute do |t| + # t.import(User, [{ name: 'A' }, { name: 'B' }]) + # end + # ``` # # Since DynamoDB limits the total number of actions per transaction, # each model created via +#import+ consumes one action from this limit. diff --git a/lib/dynamoid/transactions/mutation/base.rb b/lib/dynamoid/transactions/mutation/base.rb index e2e799cc..0d7eb964 100644 --- a/lib/dynamoid/transactions/mutation/base.rb +++ b/lib/dynamoid/transactions/mutation/base.rb @@ -3,6 +3,7 @@ module Dynamoid module Transactions class Mutation + # @private class Base # Callback called at "initialization" or "registration" an action # before changes are persisted. It's a proper place to validate diff --git a/lib/dynamoid/transactions/mutation/builders/delete_request_builder.rb b/lib/dynamoid/transactions/mutation/builders/delete_request_builder.rb index 38229bfe..f5c28c94 100644 --- a/lib/dynamoid/transactions/mutation/builders/delete_request_builder.rb +++ b/lib/dynamoid/transactions/mutation/builders/delete_request_builder.rb @@ -3,8 +3,8 @@ module Dynamoid module Transactions class Mutation + # @private module Builders - # @private class DeleteRequestBuilder attr_writer :hash_key, :range_key, :condition_expression diff --git a/lib/dynamoid/transactions/mutation/builders/update_request_builder.rb b/lib/dynamoid/transactions/mutation/builders/update_request_builder.rb index a103a4b5..52f5387c 100644 --- a/lib/dynamoid/transactions/mutation/builders/update_request_builder.rb +++ b/lib/dynamoid/transactions/mutation/builders/update_request_builder.rb @@ -3,8 +3,8 @@ module Dynamoid module Transactions class Mutation + # @private module Builders - # @private class UpdateRequestBuilder attr_writer :hash_key, :range_key, :condition_expression diff --git a/lib/dynamoid/transactions/mutation/create.rb b/lib/dynamoid/transactions/mutation/create.rb index 021ba9a8..ad21013f 100644 --- a/lib/dynamoid/transactions/mutation/create.rb +++ b/lib/dynamoid/transactions/mutation/create.rb @@ -5,6 +5,7 @@ module Dynamoid module Transactions class Mutation + # @private class Create < Base def initialize(model_class, attributes = {}, **options, &block) super() diff --git a/lib/dynamoid/transactions/mutation/delete_with_instance.rb b/lib/dynamoid/transactions/mutation/delete_with_instance.rb index 29256e3a..89af91d0 100644 --- a/lib/dynamoid/transactions/mutation/delete_with_instance.rb +++ b/lib/dynamoid/transactions/mutation/delete_with_instance.rb @@ -6,6 +6,7 @@ module Dynamoid module Transactions class Mutation + # @private class DeleteWithInstance < Base def initialize(model) super() diff --git a/lib/dynamoid/transactions/mutation/delete_with_primary_key.rb b/lib/dynamoid/transactions/mutation/delete_with_primary_key.rb index 1067e1bc..b642d10c 100644 --- a/lib/dynamoid/transactions/mutation/delete_with_primary_key.rb +++ b/lib/dynamoid/transactions/mutation/delete_with_primary_key.rb @@ -6,6 +6,7 @@ module Dynamoid module Transactions class Mutation + # @private class DeleteWithPrimaryKey < Base def initialize(model_class, hash_key, range_key) super() diff --git a/lib/dynamoid/transactions/mutation/destroy.rb b/lib/dynamoid/transactions/mutation/destroy.rb index 7e242083..8e844860 100644 --- a/lib/dynamoid/transactions/mutation/destroy.rb +++ b/lib/dynamoid/transactions/mutation/destroy.rb @@ -6,6 +6,7 @@ module Dynamoid module Transactions class Mutation + # @private class Destroy < Base def initialize(model, **options) super() diff --git a/lib/dynamoid/transactions/mutation/inc.rb b/lib/dynamoid/transactions/mutation/inc.rb index 3d76665b..74db63b4 100644 --- a/lib/dynamoid/transactions/mutation/inc.rb +++ b/lib/dynamoid/transactions/mutation/inc.rb @@ -6,6 +6,7 @@ module Dynamoid module Transactions class Mutation + # @private class Inc < Base def initialize(model_class, hash_key, range_key, counters) super() diff --git a/lib/dynamoid/transactions/mutation/save.rb b/lib/dynamoid/transactions/mutation/save.rb index 04946219..2ccf87e1 100644 --- a/lib/dynamoid/transactions/mutation/save.rb +++ b/lib/dynamoid/transactions/mutation/save.rb @@ -6,6 +6,7 @@ module Dynamoid module Transactions class Mutation + # @private class Save < Base def initialize(model, **options) super() diff --git a/lib/dynamoid/transactions/mutation/update_attributes.rb b/lib/dynamoid/transactions/mutation/update_attributes.rb index 0285b07b..f9793ade 100644 --- a/lib/dynamoid/transactions/mutation/update_attributes.rb +++ b/lib/dynamoid/transactions/mutation/update_attributes.rb @@ -6,6 +6,7 @@ module Dynamoid module Transactions class Mutation + # @private class UpdateAttributes < Base def initialize(model, attributes, **options) super() diff --git a/lib/dynamoid/transactions/mutation/update_fields.rb b/lib/dynamoid/transactions/mutation/update_fields.rb index be9711e1..8693b889 100644 --- a/lib/dynamoid/transactions/mutation/update_fields.rb +++ b/lib/dynamoid/transactions/mutation/update_fields.rb @@ -6,8 +6,8 @@ module Dynamoid module Transactions class Mutation + # @private class UpdateFields < Base - # @private class ItemUpdater attr_reader :attributes_to_set, :attributes_to_add, :attributes_to_delete, :attributes_to_remove diff --git a/lib/dynamoid/transactions/mutation/upsert.rb b/lib/dynamoid/transactions/mutation/upsert.rb index 0cd69288..9c26d39c 100644 --- a/lib/dynamoid/transactions/mutation/upsert.rb +++ b/lib/dynamoid/transactions/mutation/upsert.rb @@ -6,6 +6,7 @@ module Dynamoid module Transactions class Mutation + # @private class Upsert < Base def initialize(model_class, hash_key, range_key, attributes) super() diff --git a/lib/dynamoid/transactions/retrieval.rb b/lib/dynamoid/transactions/retrieval.rb index 01c87d3b..e0d429ba 100644 --- a/lib/dynamoid/transactions/retrieval.rb +++ b/lib/dynamoid/transactions/retrieval.rb @@ -11,13 +11,15 @@ module Transactions # The reading methods are supposed to be as close as possible to their # non-transactional counterparts: # - # user_id = params[:user_id] - # payment = params[:payment_id] + # ``` + # user_id = params[:user_id] + # payment = params[:payment_id] # - # models = Dynamoid::Transactions::Retrieval.execute do |t| - # t.find User, user_id - # t.find Payment, payment_id - # end + # models = Dynamoid::Transactions::Retrieval.execute do |t| + # t.find User, user_id + # t.find Payment, payment_id + # end + # ``` # # The only difference is that the methods are called on a transaction # instance and a model or a model class should be specified. So +User.find+ diff --git a/lib/dynamoid/transactions/retrieval/find.rb b/lib/dynamoid/transactions/retrieval/find.rb index 972b5c58..3f69a3fc 100644 --- a/lib/dynamoid/transactions/retrieval/find.rb +++ b/lib/dynamoid/transactions/retrieval/find.rb @@ -3,6 +3,7 @@ module Dynamoid module Transactions class Retrieval + # @private class Find attr_reader :model_class