Class: Sequel::Schema::DbIndex
- Inherits:
-
Object
- Object
- Sequel::Schema::DbIndex
- Defined in:
- lib/sequel/schema/db_index.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
-
.build_from_hash(definitions) ⇒ Object
Builds an Array of DbIndexes from the index hash returned by Sequel::Database#indexes.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
Indexes are equal if all their attributes are equal.
-
#add_statement ⇒ Object
Returns the sequel migration statement to add an index in an alter_table block.
-
#define_statement ⇒ Object
Returns the sequel migration statement to define an index in a create_table block.
-
#drop_statement ⇒ Object
Returns the sequel migration statement to remove an index in an alter_table block.
-
#hash ⇒ Object
:nodoc:.
-
#initialize(name, columns, unique = false) ⇒ DbIndex
constructor
Creates a new DbIndex definition.
-
#multi_column? ⇒ Boolean
Returns true if this index has more than one column.
-
#unique? ⇒ Boolean
Returns true if this index is unique.
Constructor Details
#initialize(name, columns, unique = false) ⇒ DbIndex
Creates a new DbIndex definition.
columns may be a single column name as a symbol, or an array of column symbol names.
Indexes are not unique by default.
19 20 21 22 23 |
# File 'lib/sequel/schema/db_index.rb', line 19 def initialize(name, columns, unique=false) @name = name.to_sym @columns = columns.kind_of?(Array) ? columns.clone : [columns] @unique = !! unique end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
5 6 7 |
# File 'lib/sequel/schema/db_index.rb', line 5 def columns @columns end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/sequel/schema/db_index.rb', line 4 def name @name end |
Class Method Details
.build_from_hash(definitions) ⇒ Object
Builds an Array of DbIndexes from the index hash returned by Sequel::Database#indexes
9 10 11 |
# File 'lib/sequel/schema/db_index.rb', line 9 def self.build_from_hash(definitions) definitions.map {|name,attrs| new(name, attrs[:columns], attrs[:unique]) } end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
Indexes are equal if all their attributes are equal.
54 55 56 57 |
# File 'lib/sequel/schema/db_index.rb', line 54 def ==(other) other.kind_of?(self.class) && @name == other.name && @columns == other.columns && @unique == other.unique? end |
#add_statement ⇒ Object
Returns the sequel migration statement to add an index in an alter_table block.
43 44 45 |
# File 'lib/sequel/schema/db_index.rb', line 43 def add_statement base_add_statement('add_index') end |
#define_statement ⇒ Object
Returns the sequel migration statement to define an index in a create_table block.
37 38 39 |
# File 'lib/sequel/schema/db_index.rb', line 37 def define_statement base_add_statement('index') end |
#drop_statement ⇒ Object
Returns the sequel migration statement to remove an index in an alter_table block.
49 50 51 |
# File 'lib/sequel/schema/db_index.rb', line 49 def drop_statement "drop_index #{columns_for_statement.inspect}, :name => #{name.inspect}" end |
#hash ⇒ Object
:nodoc:
60 61 62 |
# File 'lib/sequel/schema/db_index.rb', line 60 def hash # :nodoc: @name.hash end |
#multi_column? ⇒ Boolean
Returns true if this index has more than one column.
31 32 33 |
# File 'lib/sequel/schema/db_index.rb', line 31 def multi_column? @columns.size > 1 end |
#unique? ⇒ Boolean
Returns true if this index is unique
26 27 28 |
# File 'lib/sequel/schema/db_index.rb', line 26 def unique? @unique end |