Module: SchemaPlus::ActiveRecord::ConnectionAdapters::IndexDefinition

Defined in:
lib/schema_plus/active_record/connection_adapters/index_definition.rb

Overview

SchemaPlus extends the IndexDefinition object to return information about partial indexes and case sensitivity (i.e. Postgresql support).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#conditionsObject

Returns the value of attribute conditions


13
14
15
# File 'lib/schema_plus/active_record/connection_adapters/index_definition.rb', line 13

def conditions
  @conditions
end

#expressionObject (readonly)

Returns the value of attribute expression


14
15
16
# File 'lib/schema_plus/active_record/connection_adapters/index_definition.rb', line 14

def expression
  @expression
end

#kindObject (readonly)

Returns the value of attribute kind


15
16
17
# File 'lib/schema_plus/active_record/connection_adapters/index_definition.rb', line 15

def kind
  @kind
end

#operator_classesObject (readonly)

Returns the value of attribute operator_classes


16
17
18
# File 'lib/schema_plus/active_record/connection_adapters/index_definition.rb', line 16

def operator_classes
  @operator_classes
end

Class Method Details

.included(base) ⇒ Object

:nodoc:


9
10
11
# File 'lib/schema_plus/active_record/connection_adapters/index_definition.rb', line 9

def self.included(base)  #:nodoc:
  base.alias_method_chain :initialize, :schema_plus
end

Instance Method Details

#==(other) ⇒ Object

tests if the corresponding indexes would be the same


54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/schema_plus/active_record/connection_adapters/index_definition.rb', line 54

def ==(other)
  return false if other.nil?
  return false unless self.name == other.name
  return false unless Array.wrap(self.columns).collect(&:to_s).sort == Array.wrap(other.columns).collect(&:to_s).sort
  return false unless !!self.unique == !!other.unique
  return false unless Array.wrap(self.lengths).compact.sort == Array.wrap(other.lengths).compact.sort
  return false unless self.conditions == other.conditions
  return false unless self.expression == other.expression
  return false unless self.kind == other.kind
  return false unless self.operator_classes == other.operator_classes
  return false unless !!self.case_sensitive? == !!other.case_sensitive?
  true
end

#case_sensitive?Boolean

Returns:

  • (Boolean)

18
19
20
# File 'lib/schema_plus/active_record/connection_adapters/index_definition.rb', line 18

def case_sensitive?
  @case_sensitive
end

#initialize_with_schema_plus(*args) ⇒ Object

:nodoc:


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/schema_plus/active_record/connection_adapters/index_definition.rb', line 22

def initialize_with_schema_plus(*args) #:nodoc:
  # same args as add_index(table_name, column_names, options)
  if args.length == 3 and Hash === args.last
    table_name, column_names, options = args + [{}]
    initialize_without_schema_plus(table_name, options[:name], options[:unique], column_names, options[:length], options[:orders])
    @conditions = options[:conditions]
    @expression = options[:expression]
    @kind = options[:kind]
    @case_sensitive = options.include?(:case_sensitive) ? options[:case_sensitive] : true
    @operator_classes = options[:operator_classes] || {}
  else # backwards compatibility
    initialize_without_schema_plus(*args)
    @case_sensitive = true
    @operator_classes = {}
  end
end

#optsObject

returns the options as a hash suitable for add_index


40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/schema_plus/active_record/connection_adapters/index_definition.rb', line 40

def opts #:nodoc:
  opts = {}
  opts[:name]           = name unless name.nil?
  opts[:unique]         = unique unless unique.nil?
  opts[:length]         = lengths unless lengths.nil?
  opts[:conditions]     = conditions unless conditions.nil?
  opts[:expression]     = expression unless expression.nil?
  opts[:kind]           = kind unless kind.nil?
  opts[:case_sensitive] = case_sensitive? unless @case_sensitive.nil?
  opts[:operator_classes] = @operator_classes unless @operator_classes.nil?
  opts
end