Class: Peegee::Constraint
- Inherits:
-
Object
- Object
- Peegee::Constraint
- Defined in:
- lib/peegee/constraint.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#create ⇒ Object
Creates this constraint definition.
-
#drop ⇒ Object
Drops this constraint.
-
#initialize(opts = {}) ⇒ Constraint
constructor
A new instance of Constraint.
-
#to_s ⇒ Object
Returns human readable constraint.
Constructor Details
#initialize(opts = {}) ⇒ Constraint
Returns a new instance of Constraint.
4 5 6 7 8 |
# File 'lib/peegee/constraint.rb', line 4 def initialize(opts = {}) @table_name = opts[:table_name] @constraint_name = opts[:constraint_name] @constraint_def = opts[:constraint_def] end |
Instance Method Details
#create ⇒ Object
Creates this constraint definition.
16 17 18 19 |
# File 'lib/peegee/constraint.rb', line 16 def create sql = "alter table #{@table_name} add constraint #{@constraint_name} #{@constraint_def}" ActiveRecord::Base.connection.execute(sql) end |
#drop ⇒ Object
Drops this constraint.
22 23 24 25 |
# File 'lib/peegee/constraint.rb', line 22 def drop sql = "alter table #{@table_name} drop constraint #{@constraint_name}" ActiveRecord::Base.connection.execute(sql) end |
#to_s ⇒ Object
Returns human readable constraint.
11 12 13 |
# File 'lib/peegee/constraint.rb', line 11 def to_s "Constraint: #{@constraint_name} on #{table_name}" end |