Sha256: f406ff3bf6ed22db8ed56b733cbe64ad0207c5df02f8eb8450918181141748f6

Contents?: true

Size: 992 Bytes

Versions: 9

Compression:

Stored size: 992 Bytes

Contents

# frozen_string_literal: true

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
        if !defined?(@sequential_updates)
          if sequential_updates_option.nil?
            table_exists =
              if ActiveRecord::VERSION::MAJOR >= 5
                caller_class.connection.data_source_exists?(caller_class.table_name)
              else
                caller_class.connection.table_exists?(caller_class.table_name)
              end
            index_exists = caller_class.connection.index_exists?(caller_class.table_name, column, unique: true)
            @sequential_updates = table_exists && index_exists
          else
            @sequential_updates = sequential_updates_option
          end
        else
          @sequential_updates
        end
      end

      private :sequential_updates?
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
acts_as_list-0.9.19 lib/acts_as_list/active_record/acts/sequential_updates_method_definer.rb
acts_as_list-0.9.18 lib/acts_as_list/active_record/acts/sequential_updates_method_definer.rb
acts_as_list-0.9.17 lib/acts_as_list/active_record/acts/sequential_updates_method_definer.rb
acts_as_list-0.9.16 lib/acts_as_list/active_record/acts/sequential_updates_method_definer.rb
acts_as_list-0.9.15 lib/acts_as_list/active_record/acts/sequential_updates_method_definer.rb
acts_as_list-0.9.14 lib/acts_as_list/active_record/acts/sequential_updates_method_definer.rb
acts_as_list-0.9.13 lib/acts_as_list/active_record/acts/sequential_updates_method_definer.rb
acts_as_list-0.9.12 lib/acts_as_list/active_record/acts/sequential_updates_method_definer.rb
acts_as_list-0.9.11 lib/acts_as_list/active_record/acts/sequential_updates_method_definer.rb