Class: PGExaminer::Result::Column

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

Instance Attribute Summary

Attributes inherited from Item

#parent, #result, #row

Instance Method Summary collapse

Methods inherited from Item

#inspect, #name, #oid

Methods inherited from Base

#==, #diff, #diffable_lists

Constructor Details

#initialize(*args) ⇒ Column

Returns a new instance of Column.



6
7
8
9
# File 'lib/pg_examiner/result/column.rb', line 6

def initialize(*args)
  super
  @default_calculated = false
end

Instance Method Details

#defaultObject



31
32
33
34
35
36
37
38
39
# File 'lib/pg_examiner/result/column.rb', line 31

def default
  # Have to dance a bit so that the lack of a default becomes nil, but isn't recalculated each time.
  if @default_calculated
    @default
  else
    @default_calculated = true
    @default = result.pg_attrdef.find{|d| d['adrelid'] == row['attrelid'] && d['adnum'] == row['attnum']}['default'] if row['atthasdef'] == 't'
  end
end

#diffable_attrsObject



18
19
20
21
22
23
24
25
# File 'lib/pg_examiner/result/column.rb', line 18

def diffable_attrs
  {
    'name'       => "name",
    'attndims'   => "array dimensionality",
    'attnotnull' => "column is marked not-null",
    'atttypmod'  => "datatype information (atttypmod)",
  }
end

#diffable_methodsObject



11
12
13
14
15
16
# File 'lib/pg_examiner/result/column.rb', line 11

def diffable_methods
  {
    "type"    => "type",
    "default" => "default"
  }
end

#typeObject



27
28
29
# File 'lib/pg_examiner/result/column.rb', line 27

def type
  @type ||= result.pg_type.find{|t| t['oid'] == row['atttypid']}['name']
end