class OnlineMigrations::IndexesCollector

@private

Constants

COLUMN_TYPES

Attributes

indexes[R]

Public Class Methods

new() click to toggle source
# File lib/online_migrations/indexes_collector.rb, line 11
def initialize
  @indexes = []
end

Public Instance Methods

belongs_to(*_ref_names, **options)
Alias for: references
collect(&table_definition) click to toggle source
# File lib/online_migrations/indexes_collector.rb, line 15
def collect(&table_definition)
  table_definition.call(self)
end
index(_column_name, **options) click to toggle source
# File lib/online_migrations/indexes_collector.rb, line 19
def index(_column_name, **options)
  @indexes << IndexDefinition.new(using: options[:using].to_s)
end
method_missing(method_name, *_args, **options) click to toggle source
# File lib/online_migrations/indexes_collector.rb, line 33
def method_missing(method_name, *_args, **options)
  # Check for type-based methods, where we can also specify an index:
  # t.string :email, index: true
  if COLUMN_TYPES.include?(method_name)
    index = options.fetch(:index, false)

    if index
      using = index.is_a?(Hash) ? index[:using].to_s : nil
      @indexes << IndexDefinition.new(using: using)
    end
  end
end
references(*_ref_names, **options) click to toggle source
# File lib/online_migrations/indexes_collector.rb, line 23
def references(*_ref_names, **options)
  index = options.fetch(:index) { Utils.ar_version >= 5.0 }

  if index
    using = index.is_a?(Hash) ? index[:using].to_s : nil
    @indexes << IndexDefinition.new(using: using)
  end
end
Also aliased as: belongs_to