Module: SchemaPlus::Indexes::ActiveRecord::ConnectionAdapters::IndexDefinition
- Defined in:
- lib/schema_plus/indexes/active_record/connection_adapters/index_definition.rb
Instance Attribute Summary collapse
-
#orders ⇒ Object
Returns the value of attribute orders.
Instance Method Summary collapse
-
#==(other) ⇒ Object
tests if the corresponding indexes would be the same.
-
#initialize(*args) ⇒ Object
:nodoc:.
Instance Attribute Details
#orders ⇒ Object
Returns the value of attribute orders.
7 8 9 |
# File 'lib/schema_plus/indexes/active_record/connection_adapters/index_definition.rb', line 7 def orders @orders end |
Instance Method Details
#==(other) ⇒ Object
tests if the corresponding indexes would be the same
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/schema_plus/indexes/active_record/connection_adapters/index_definition.rb', line 46 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:
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/schema_plus/indexes/active_record/connection_adapters/index_definition.rb', line 9 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, .except(:name, :unique) else # backwards compatibility super end 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 |