Class: Dumbo::PgObject

Inherits:
Object
  • Object
show all
Defined in:
lib/dumbo/pg_object.rb

Direct Known Subclasses

Aggregate, Cast, Function, Operator, Type

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(oid) ⇒ PgObject

Returns a new instance of PgObject.



14
15
16
17
# File 'lib/dumbo/pg_object.rb', line 14

def initialize(oid)
  @oid = oid
  load_attributes
end

Instance Attribute Details

#oidObject (readonly)

Returns the value of attribute oid.



5
6
7
# File 'lib/dumbo/pg_object.rb', line 5

def oid
  @oid
end

Class Method Details

.identfied_by(*args) ⇒ Object



9
10
11
# File 'lib/dumbo/pg_object.rb', line 9

def identfied_by(*args)
  self.identifier = args
end

Instance Method Details

#downgrade(other) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/dumbo/pg_object.rb', line 60

def downgrade(other)
  return self.drop if other.nil?

  if other.identify != self.identify
    raise "Not the Same Objects!"
  end

  if other.to_sql != self.to_sql
     "    \#{self.drop}\n    \#{other.to_sql}\n    SQL\n  end\nend\n".gsub(/^ {8}/, '')

#execute(sql) ⇒ Object



75
76
77
# File 'lib/dumbo/pg_object.rb', line 75

def execute(sql)
  ActiveRecord::Base.connection.execute(sql)
end

#get(type = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dumbo/pg_object.rb', line 23

def get(type=nil)
  case type
  when 'function', 'pg_proc'
    Function.new(oid).get
  when 'cast', 'pg_cast'
    Cast.new(oid).get
  when 'operator', 'pg_operator'
    Operator.new(oid).get
  when 'type', 'pg_type'
    Type.new(oid).get
  else
    self.load_attributes
    self
  end
end

#identifyObject



19
20
21
# File 'lib/dumbo/pg_object.rb', line 19

def identify
   identifier.map{|a| public_send a}
end

#load_attributesObject



39
40
41
# File 'lib/dumbo/pg_object.rb', line 39

def load_attributes

end

#upgrade(other) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/dumbo/pg_object.rb', line 43

def upgrade(other)
  return self.to_sql if other.nil?

  if other.identify != self.identify
    raise "Not the Same Objects!"
  end

  if other.to_sql != self.to_sql
     "    \#{self.drop}\n    \#{self.to_sql}\n    SQL\n  end\n\n\nend\n".gsub(/^ {8}/, '')