Class: MysqlInspector::Constraint
- Inherits:
-
Struct
- Object
- Struct
- MysqlInspector::Constraint
- Includes:
- TablePart
- Defined in:
- lib/mysql_inspector/constraint.rb
Instance Attribute Summary collapse
-
#column_names ⇒ Object
Returns the value of attribute column_names.
-
#foreign_column_names ⇒ Object
Returns the value of attribute foreign_column_names.
-
#foreign_table ⇒ Object
Returns the value of attribute foreign_table.
-
#name ⇒ Object
Returns the value of attribute name.
-
#on_delete ⇒ Object
Returns the value of attribute on_delete.
-
#on_update ⇒ Object
Returns the value of attribute on_update.
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/constraint.rb', line 2 def column_names @column_names end |
#foreign_column_names ⇒ Object
Returns the value of attribute foreign_column_names
2 3 4 |
# File 'lib/mysql_inspector/constraint.rb', line 2 def foreign_column_names @foreign_column_names end |
#foreign_table ⇒ Object
Returns the value of attribute foreign_table
2 3 4 |
# File 'lib/mysql_inspector/constraint.rb', line 2 def foreign_table @foreign_table end |
#name ⇒ Object
Returns the value of attribute name
2 3 4 |
# File 'lib/mysql_inspector/constraint.rb', line 2 def name @name end |
#on_delete ⇒ Object
Returns the value of attribute on_delete
2 3 4 |
# File 'lib/mysql_inspector/constraint.rb', line 2 def on_delete @on_delete end |
#on_update ⇒ Object
Returns the value of attribute 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_sql ⇒ Object
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 |