Module: ActiveRecord::Acts::List::SequentialUpdatesMethodDefiner

Defined in:
lib/acts_as_list/active_record/acts/sequential_updates_method_definer.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.call(caller_class, column, sequential_updates_option) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/acts_as_list/active_record/acts/sequential_updates_method_definer.rb', line 6

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