Sha256: 2b9b9cf906e4cd3e27a4a042386354a3371d93406d8e08428a1ee8cfa5ebec12

Contents?: true

Size: 1016 Bytes

Versions: 3

Compression:

Stored size: 1016 Bytes

Contents

# frozen_string_literal: true

require_relative './with_connection'

module ActiveRecord::Acts::List::SequentialUpdatesMethodDefiner #:nodoc:
  def self.call(caller_class, column, sequential_updates_option)
    caller_class.class_eval do
      define_method :sequential_updates? do
        return @sequential_updates if defined?(@sequential_updates)

        return @sequential_updates = sequential_updates_option unless sequential_updates_option.nil?

        ActiveRecord::Acts::List::WithConnection.new(caller_class).call do |connection|
          table_exists =
            if active_record_version_is?('>= 5')
              connection.data_source_exists?(caller_class.table_name)
            else
              connection.table_exists?(caller_class.table_name)
            end
          index_exists = connection.index_exists?(caller_class.table_name, column, unique: true)
          @sequential_updates = table_exists && index_exists
        end
      end

      private :sequential_updates?
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/acts_as_list-1.2.4/lib/acts_as_list/active_record/acts/sequential_updates_method_definer.rb
acts_as_list-1.2.4 lib/acts_as_list/active_record/acts/sequential_updates_method_definer.rb
acts_as_list-1.2.3 lib/acts_as_list/active_record/acts/sequential_updates_method_definer.rb