Class: MysqlInspector::Index

Inherits:
Struct
  • Object
show all
Includes:
TablePart
Defined in:
lib/mysql_inspector/index.rb

Instance Attribute Summary collapse

Attributes included from TablePart

#table

Instance Method Summary collapse

Methods included from TablePart

#<=>

Instance Attribute Details

#column_namesObject

Returns the value of attribute column_names

Returns:

  • (Object)

    the current value of column_names



2
3
4
# File 'lib/mysql_inspector/index.rb', line 2

def column_names
  @column_names
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



2
3
4
# File 'lib/mysql_inspector/index.rb', line 2

def name
  @name
end

#uniqueObject

Returns the value of attribute unique

Returns:

  • (Object)

    the current value of 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_sqlObject



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