123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::ConnectionAdapters::IndexDefinition

Do not use. This class is for internal use only.

Overview

Abstract representation of an index definition on a table. Instances of this type are typically created and returned by methods in database adapters. e.g. MySQL::SchemaStatements#indexes

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(table, name, unique = false, columns = [], lengths: {}, orders: {}, opclasses: {}, where: nil, type: nil, using: nil, include: nil, nulls_not_distinct: nil, comment: nil, valid: true) ⇒ IndexDefinition

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 11

def initialize(
  table, name,
  unique = false,
  columns = [],
  lengths: {},
  orders: {},
  opclasses: {},
  where: nil,
  type: nil,
  using: nil,
  include: nil,
  nulls_not_distinct: nil,
  comment: nil,
  valid: true
)
  @table = table
  @name = name
  @unique = unique
  @columns = columns
  @lengths = concise_options(lengths)
  @orders = concise_options(orders)
  @opclasses = concise_options(opclasses)
  @where = where
  @type = type
  @using = using
  @include = include
  @nulls_not_distinct = nulls_not_distinct
  @comment = comment
  @valid = valid
end

Instance Attribute Details

#columns (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 9

attr_reader :table, :name, :unique, :columns, :lengths, :orders, :opclasses, :where, :type, :using, :include, :nulls_not_distinct, :comment, :valid

#comment (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 9

attr_reader :table, :name, :unique, :columns, :lengths, :orders, :opclasses, :where, :type, :using, :include, :nulls_not_distinct, :comment, :valid

#include (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 9

attr_reader :table, :name, :unique, :columns, :lengths, :orders, :opclasses, :where, :type, :using, :include, :nulls_not_distinct, :comment, :valid

#lengths (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 9

attr_reader :table, :name, :unique, :columns, :lengths, :orders, :opclasses, :where, :type, :using, :include, :nulls_not_distinct, :comment, :valid

#name (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 9

attr_reader :table, :name, :unique, :columns, :lengths, :orders, :opclasses, :where, :type, :using, :include, :nulls_not_distinct, :comment, :valid

#nulls_not_distinct (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 9

attr_reader :table, :name, :unique, :columns, :lengths, :orders, :opclasses, :where, :type, :using, :include, :nulls_not_distinct, :comment, :valid

#opclasses (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 9

attr_reader :table, :name, :unique, :columns, :lengths, :orders, :opclasses, :where, :type, :using, :include, :nulls_not_distinct, :comment, :valid

#orders (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 9

attr_reader :table, :name, :unique, :columns, :lengths, :orders, :opclasses, :where, :type, :using, :include, :nulls_not_distinct, :comment, :valid

#table (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 9

attr_reader :table, :name, :unique, :columns, :lengths, :orders, :opclasses, :where, :type, :using, :include, :nulls_not_distinct, :comment, :valid

#type (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 9

attr_reader :table, :name, :unique, :columns, :lengths, :orders, :opclasses, :where, :type, :using, :include, :nulls_not_distinct, :comment, :valid

#unique (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 9

attr_reader :table, :name, :unique, :columns, :lengths, :orders, :opclasses, :where, :type, :using, :include, :nulls_not_distinct, :comment, :valid

#using (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 9

attr_reader :table, :name, :unique, :columns, :lengths, :orders, :opclasses, :where, :type, :using, :include, :nulls_not_distinct, :comment, :valid

#valid (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 9

attr_reader :table, :name, :unique, :columns, :lengths, :orders, :opclasses, :where, :type, :using, :include, :nulls_not_distinct, :comment, :valid

#valid?Boolean (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 42

def valid?
  @valid
end

#where (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 9

attr_reader :table, :name, :unique, :columns, :lengths, :orders, :opclasses, :where, :type, :using, :include, :nulls_not_distinct, :comment, :valid

Instance Method Details

#column_options

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 46

def column_options
  {
    length: lengths,
    order: orders,
    opclass: opclasses,
  }
end

#concise_options(options) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 65

def concise_options(options)
  if columns.size == options.size && options.values.uniq.size == 1
    options.values.first
  else
    options
  end
end

#defined_for?(columns = nil, name: nil, unique: nil, valid: nil, include: nil, nulls_not_distinct: nil, **options) ⇒ Boolean

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 54

def defined_for?(columns = nil, name: nil, unique: nil, valid: nil, include: nil, nulls_not_distinct: nil, **options)
  columns = options[:column] if columns.blank?
  (columns.nil? || Array(self.columns) == Array(columns).map(&:to_s)) &&
    (name.nil? || self.name == name.to_s) &&
    (unique.nil? || self.unique == unique) &&
    (valid.nil? || self.valid == valid) &&
    (include.nil? || Array(self.include) == Array(include).map(&:to_s)) &&
    (nulls_not_distinct.nil? || self.nulls_not_distinct == nulls_not_distinct)
end