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
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
-
#expression ⇒ Object
readonly
Returns the value of attribute expression.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#==(other) ⇒ Object
tests if the corresponding indexes would be the same.
- #case_sensitive? ⇒ Boolean
-
#initialize_with_schema_plus(*args) ⇒ Object
:nodoc:.
-
#opts ⇒ Object
returns the options as a hash suitable for add_index.
Instance Attribute Details
#conditions ⇒ Object (readonly)
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 |
#expression ⇒ Object (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 |
#kind ⇒ Object (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 |
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
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/schema_plus/active_record/connection_adapters/index_definition.rb', line 50 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.case_sensitive? == !!other.case_sensitive? true end |
#case_sensitive? ⇒ Boolean
17 18 19 |
# File 'lib/schema_plus/active_record/connection_adapters/index_definition.rb', line 17 def case_sensitive? @case_sensitive end |
#initialize_with_schema_plus(*args) ⇒ Object
:nodoc:
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/schema_plus/active_record/connection_adapters/index_definition.rb', line 21 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, = args + [{}] initialize_without_schema_plus(table_name, [:name], [:unique], column_names, [:length], [:orders]) @conditions = [:conditions] @expression = [:expression] @kind = [:kind] @case_sensitive = .include?(:case_sensitive) ? [:case_sensitive] : true else # backwards compatibility initialize_without_schema_plus(*args) @case_sensitive = true end end |
#opts ⇒ Object
returns the options as a hash suitable for add_index
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/schema_plus/active_record/connection_adapters/index_definition.rb', line 37 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 end |