Class: ActiveRecord::ConnectionAdapters::IndexDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/connection_adapters/abstract/schema_definitions.rb

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. ActiveRecord::ConnectionAdapters::MySQL::SchemaStatements#indexes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#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) ⇒ IndexDefinition

Returns a new instance of IndexDefinition.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 12

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

#columnsObject (readonly)

:nodoc:



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

def columns
  @columns
end

#commentObject (readonly)

:nodoc:



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

def comment
  @comment
end

#includeObject (readonly)

:nodoc:



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

def include
  @include
end

#lengthsObject (readonly)

:nodoc:



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

def lengths
  @lengths
end

#nameObject (readonly)

:nodoc:



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

def name
  @name
end

#nulls_not_distinctObject (readonly)

:nodoc:



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

def nulls_not_distinct
  @nulls_not_distinct
end

#opclassesObject (readonly)

:nodoc:



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

def opclasses
  @opclasses
end

#ordersObject (readonly)

:nodoc:



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

def orders
  @orders
end

#tableObject (readonly)

:nodoc:



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

def table
  @table
end

#typeObject (readonly)

:nodoc:



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

def type
  @type
end

#uniqueObject (readonly)

:nodoc:



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

def unique
  @unique
end

#usingObject (readonly)

:nodoc:



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

def using
  @using
end

#validObject (readonly)

:nodoc:



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

def valid
  @valid
end

#whereObject (readonly)

:nodoc:



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

def where
  @where
end

Instance Method Details

#column_optionsObject



47
48
49
50
51
52
53
# File 'lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 47

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

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

Returns:

  • (Boolean)


55
56
57
58
59
60
61
62
63
# File 'lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 55

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

#valid?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 43

def valid?
  @valid
end