Class: MysqlInspector::Index
- Inherits:
-
Struct
- Object
- Struct
- MysqlInspector::Index
- Includes:
- TablePart
- Defined in:
- lib/mysql_inspector/index.rb
Instance Attribute Summary collapse
-
#column_names ⇒ Object
Returns the value of attribute column_names.
-
#name ⇒ Object
Returns the value of attribute name.
-
#unique ⇒ Object
Returns the value of attribute unique.
Attributes included from TablePart
Instance Method Summary collapse
Methods included from TablePart
Instance Attribute Details
#column_names ⇒ Object
Returns the value of attribute column_names
2 3 4 |
# File 'lib/mysql_inspector/index.rb', line 2 def column_names @column_names end |
#name ⇒ Object
Returns the value of attribute name
2 3 4 |
# File 'lib/mysql_inspector/index.rb', line 2 def name @name end |
#unique ⇒ Object
Returns the value of attribute unique
2 3 4 |
# File 'lib/mysql_inspector/index.rb', line 2 def unique @unique end |
Instance Method Details
#=~(matcher) ⇒ Object
20 21 22 |
# File 'lib/mysql_inspector/index.rb', line 20 def =~(matcher) name =~ matcher || column_names.any? { |c| c =~ matcher } end |
#to_sql ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/mysql_inspector/index.rb', line 6 def to_sql parts = [] if name == "PRIMARY KEY" && unique parts << "PRIMARY KEY" parts << paren(column_names.map { |c| quote(c) }) else parts << "UNIQUE" if unique parts << "KEY" parts << quote(name) parts << paren(column_names.map { |c| quote(c) }) end parts * " " end |