Class: Straitjacket::Constraint
- Inherits:
-
Object
- Object
- Straitjacket::Constraint
- Defined in:
- lib/straitjacket.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#column ⇒ Object
Returns the value of attribute column.
-
#content ⇒ Object
Returns the value of attribute content.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#sql ⇒ Object
Returns the value of attribute sql.
-
#table ⇒ Object
Returns the value of attribute table.
Instance Method Summary collapse
- #apply(conn) ⇒ Object
-
#initialize(table, content, options) ⇒ Constraint
constructor
A new instance of Constraint.
Constructor Details
#initialize(table, content, options) ⇒ Constraint
Returns a new instance of Constraint.
71 72 73 74 75 76 77 |
# File 'lib/straitjacket.rb', line 71 def initialize(table, content, ) @column = [:column] @name = ([:name] || default_name(table, [:column])).to_s @table = table @content = content @options = end |
Instance Attribute Details
#column ⇒ Object
Returns the value of attribute column.
69 70 71 |
# File 'lib/straitjacket.rb', line 69 def column @column end |
#content ⇒ Object
Returns the value of attribute content.
69 70 71 |
# File 'lib/straitjacket.rb', line 69 def content @content end |
#name ⇒ Object
Returns the value of attribute name.
69 70 71 |
# File 'lib/straitjacket.rb', line 69 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
69 70 71 |
# File 'lib/straitjacket.rb', line 69 def @options end |
#sql ⇒ Object
Returns the value of attribute sql.
69 70 71 |
# File 'lib/straitjacket.rb', line 69 def sql @sql end |
#table ⇒ Object
Returns the value of attribute table.
69 70 71 |
# File 'lib/straitjacket.rb', line 69 def table @table end |
Instance Method Details
#apply(conn) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/straitjacket.rb', line 79 def apply(conn) conn.exec(sql) rescue PGError => e if e. =~ /already exists/ conn.exec(%[ALTER TABLE "#{table}" DROP CONSTRAINT "#{name}"]) retry else raise end end |