Class: PgMeta::Constraint
Direct Known Subclasses
CheckConstraint, PrimaryKeyConstraint, ReferentialConstraint, UniqueConstraint
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
List of columns in the constraint.
Attributes inherited from Node
Instance Method Summary collapse
-
#column ⇒ Object
Constraint column.
-
#initialize(table, name, columns) ⇒ Constraint
constructor
A new instance of Constraint.
-
#kind ⇒ Object
Constraint kind.
- #to_h ⇒ Object
Methods inherited from Node
#dump, #dump_value, #guid, #inspect, #sid, #to_s, #to_yaml, #uid
Constructor Details
#initialize(table, name, columns) ⇒ Constraint
Returns a new instance of Constraint.
437 438 439 440 441 442 |
# File 'lib/pg_meta/meta.rb', line 437 def initialize(table, name, columns) super(table, name) @table = table @columns = columns table.constraints[name] = self end |
Instance Attribute Details
#columns ⇒ Object (readonly)
List of columns in the constraint. Empty for CheckConstraint objects except not null constraints
432 433 434 |
# File 'lib/pg_meta/meta.rb', line 432 def columns @columns end |
Instance Method Details
#column ⇒ Object
Constraint column. Raise an error if the constraint is multi-column
425 426 427 428 |
# File 'lib/pg_meta/meta.rb', line 425 def column columns.size == 1 or raise "Multicolumn constraint" columns.first end |
#kind ⇒ Object
Constraint kind. Either :primary_key, :unique, :check, or :referential
435 |
# File 'lib/pg_meta/meta.rb', line 435 def kind() CONSTRAINT_KINDS[self.class] end |
#to_h ⇒ Object
444 |
# File 'lib/pg_meta/meta.rb', line 444 def to_h() attrs_to_h(:name, :kind, :columns) end |