Class: PgMeta::Constraint

Inherits:
Node
  • Object
show all
Defined in:
lib/pg_meta/meta.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#name, #parent, #root

Instance Method Summary collapse

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

#columnsObject (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

#columnObject

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

#kindObject

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_hObject



444
# File 'lib/pg_meta/meta.rb', line 444

def to_h() attrs_to_h(:name, :kind, :columns) end