Module: SchemaPlus::Indexes::ActiveRecord::ConnectionAdapters::IndexDefinition
- Defined in:
- lib/schema_plus/indexes/active_record/connection_adapters/index_definition.rb
Instance Method Summary collapse
-
#==(other) ⇒ Object
tests if the corresponding indexes would be the same.
-
#initialize(*args) ⇒ Object
:nodoc:.
Instance Method Details
#==(other) ⇒ Object
tests if the corresponding indexes would be the same
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/schema_plus/indexes/active_record/connection_adapters/index_definition.rb', line 23 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 if self.lengths.is_a?(Hash) or other.lengths.is_a?(Hash) return false if (self.lengths || {}) != (other.lengths || {}) # treat nil same as empty hash else return false if Array.wrap(self.lengths).compact.sort != Array.wrap(other.lengths).compact.sort end return false unless self.where == other.where return false unless (self.using||:btree) == (other.using||:btree) true end |
#initialize(*args) ⇒ Object
:nodoc:
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/schema_plus/indexes/active_record/connection_adapters/index_definition.rb', line 7 def initialize(*args) #:nodoc: # same args as add_index(table_name, column_names, options) if args.length == 3 and Hash === args.last table_name, column_names, = args + [{}] super table_name, [:name], [:unique], column_names, [:length], [:orders], [:where], [:type], [:using] else # backwards compatibility super end unless orders.blank? # fill out orders with :asc when undefined. make sure hash ordering # follows column ordering. self.orders = Hash[columns.map{|column| [column, orders[column] || :asc]}] end end |