Class: PGExaminer::Result::Table

Inherits:
Item
  • Object
show all
Defined in:
lib/pg_examiner/result/table.rb

Defined Under Namespace

Classes: Permission

Instance Attribute Summary

Attributes inherited from Item

#parent, #result, #row

Instance Method Summary collapse

Methods inherited from Item

#initialize, #inspect, #name, #oid

Methods inherited from Base

#==, #diff, #diffable_methods

Constructor Details

This class inherits a constructor from PGExaminer::Result::Item

Instance Method Details

#columnsObject



24
25
26
27
28
# File 'lib/pg_examiner/result/table.rb', line 24

def columns
  @columns ||= result.pg_attribute.select do |c|
    c['attrelid'] == oid
  end.sort_by{|c| c['name']}.map { |row| Column.new(result, row, self) }
end

#constraintsObject



36
37
38
39
40
# File 'lib/pg_examiner/result/table.rb', line 36

def constraints
  @constraints ||= result.pg_constraint.select do |c|
    c['conrelid'] == oid
  end.map{|row| Constraint.new(result, row, self)}.sort_by(&:name)
end

#diffable_attrsObject



16
17
18
19
20
21
22
# File 'lib/pg_examiner/result/table.rb', line 16

def diffable_attrs
  {
    "name"           => "name",
    "relpersistence" => "table type (relpersistence)",
    "reloptions"     => "table options",
  }
end

#diffable_listsObject



6
7
8
9
10
11
12
13
14
# File 'lib/pg_examiner/result/table.rb', line 6

def diffable_lists
  {
    "columns"     => "columns",
    "indexes"     => "indexes",
    "constraints" => "constraints",
    "triggers"    => "triggers",
    "permissions" => "permissions",
  }
end

#indexesObject



30
31
32
33
34
# File 'lib/pg_examiner/result/table.rb', line 30

def indexes
  @indexes ||= result.pg_index.select do |c|
    c['indrelid'] == oid
  end.map{|row| Index.new(result, row, self)}.sort_by(&:name)
end

#permissionsObject



48
49
50
51
52
53
54
55
56
# File 'lib/pg_examiner/result/table.rb', line 48

def permissions
  @permissions ||= begin
    if acl = @row["relacl"]
      acl[/^{(.*)}$/, 1].split(",").map{|acl| Permission.new(acl)}.sort_by(&:name)
    else
      []
    end
  end
end

#triggersObject



42
43
44
45
46
# File 'lib/pg_examiner/result/table.rb', line 42

def triggers
  @triggers ||= result.pg_trigger.select do |t|
    t['tgrelid'] == oid
  end.map{|row| Trigger.new(result, row, self)}.sort_by(&:name)
end