Sha256: 18fe0056aa6cf267f18c652d4af34ed279c405de8875b989c219c2741eef6f26

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

require 'dynamoid/criteria/chain'

module Dynamoid
  # Allows classes to be queried by where, all, first, and each and return criteria chains.
  module Criteria
    extend ActiveSupport::Concern

    # @private
    module ClassMethods
      %i[
        where consistent all first last delete_all destroy_all each record_limit
        scan_limit batch start scan_index_forward find_by_pages project pluck
      ].each do |name|
        # Return a criteria chain in response to a method that will begin or end a chain. For more information,
        # see Dynamoid::Criteria::Chain.
        #
        # @since 0.2.0
        define_method(name) do |*args, &blk|
          # Don't use keywork arguments delegating (with **kw). It works in
          # different way in different Ruby versions: <= 2.6, 2.7, 3.0 and in some
          # future 3.x versions. Providing that there are no downstream methods
          # with keyword arguments in Chain.
          #
          # https://eregon.me/blog/2019/11/10/the-delegation-challenge-of-ruby27.html

          chain = Dynamoid::Criteria::Chain.new(self)
          chain.send(name, *args, &blk)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dynamoid-3.10.0 lib/dynamoid/criteria.rb
dynamoid-3.9.0 lib/dynamoid/criteria.rb
dynamoid-3.8.0 lib/dynamoid/criteria.rb