Class: MysqlInspector::Constraint

Inherits:
Struct
  • Object
show all
Includes:
TablePart
Defined in:
lib/mysql_inspector/constraint.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/constraint.rb', line 2

def column_names
  @column_names
end

#foreign_column_namesObject

Returns the value of attribute foreign_column_names

Returns:

  • (Object)

    the current value of foreign_column_names



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

def foreign_column_names
  @foreign_column_names
end

#foreign_tableObject

Returns the value of attribute foreign_table

Returns:

  • (Object)

    the current value of foreign_table



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

def foreign_table
  @foreign_table
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



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

def name
  @name
end

#on_deleteObject

Returns the value of attribute on_delete

Returns:

  • (Object)

    the current value of on_delete



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

def on_delete
  @on_delete
end

#on_updateObject

Returns the value of attribute on_update

Returns:

  • (Object)

    the current value of on_update



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

def on_update
  @on_update
end

Instance Method Details

#=~(matcher) ⇒ Object



20
21
22
23
24
25
# File 'lib/mysql_inspector/constraint.rb', line 20

def =~(matcher)
  name =~ matcher ||
    column_names.any? { |c| c =~ matcher } ||
    foreign_table =~ matcher ||
    foreign_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/constraint.rb', line 6

def to_sql
  parts = []
  parts << "CONSTRAINT"
  parts << quote(name)
  parts << "FOREIGN KEY"
  parts << paren(column_names.map { |c| quote(c) })
  parts << "REFERENCES"
  parts << quote(foreign_table)
  parts << paren(foreign_column_names.map { |c| quote(c) })
  parts << "ON DELETE #{on_delete}"
  parts << "ON UPDATE #{on_update}"
  parts * " "
end