Class: SexyPgConstraints::Deconstrainer
- Inherits:
-
Object
- Object
- SexyPgConstraints::Deconstrainer
show all
- Extended by:
- Helpers
- Defined in:
- lib/sexy_pg_constraints/constrainers/deconstrainer.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Helpers
execute, make_title
Constructor Details
#initialize(table, columns = []) ⇒ Deconstrainer
Returns a new instance of Deconstrainer.
7
8
9
10
|
# File 'lib/sexy_pg_constraints/constrainers/deconstrainer.rb', line 7
def initialize(table, columns = [])
@table = table.to_s
@columns = columns
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(column, *constraints) ⇒ Object
12
13
14
|
# File 'lib/sexy_pg_constraints/constrainers/deconstrainer.rb', line 12
def method_missing(column, *constraints)
self.class.drop_constraints(@table, column.to_s, *constraints)
end
|
Class Method Details
.drop_constraints(table, column, *constraints) ⇒ Object
26
27
28
29
30
|
# File 'lib/sexy_pg_constraints/constrainers/deconstrainer.rb', line 26
def drop_constraints(table, column, *constraints)
constraints.each do |type|
execute "alter table #{table} drop constraint #{make_title(table, column, type)};"
end
end
|
Instance Method Details
#[](*columns) ⇒ Object
16
17
18
19
|
# File 'lib/sexy_pg_constraints/constrainers/deconstrainer.rb', line 16
def [](*columns)
@columns = columns.map{|c| c.to_s}
self
end
|
#all(*constraints) ⇒ Object
21
22
23
|
# File 'lib/sexy_pg_constraints/constrainers/deconstrainer.rb', line 21
def all(*constraints)
self.class.drop_constraints(@table, @columns, *constraints)
end
|