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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ordersObject

Returns the value of attribute orders.



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

def orders
  @orders
end

Instance Method Details

#==(other) ⇒ Object

tests if the corresponding indexes would be the same



25
26
27
28
29
30
31
32
33
34
# File 'lib/schema_plus/indexes/active_record/connection_adapters/index_definition.rb', line 25

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 if (self.lengths || {}) != (other.lengths || {}) # treat nil same as empty hash
  return false unless self.where == other.where
  return false unless (self.using||:btree) == (other.using||:btree)
  true
end

#initialize(*args, **kwargs) ⇒ Object

:nodoc:



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/schema_plus/indexes/active_record/connection_adapters/index_definition.rb', line 10

def initialize(*args, **kwargs) #:nodoc:
  super

  unless orders.blank?
    # fill out orders with :asc when undefined.  make sure hash ordering
    # follows column ordering.
    if self.orders.is_a?(Hash)
      self.orders = Hash[columns.map{|column| [column, orders[column] || :asc]}]
    else
      self.orders = Hash[columns.map{|column| [column, orders || :asc]}]
    end
  end
end