Class: Dumbo::PgObject
- Inherits:
-
Object
show all
- Defined in:
- lib/dumbo/pg_object.rb
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
#oid ⇒ Object
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/dumbo/pg_object.rb', line 57
def downgrade(other)
return drop if other.nil?
if other.identify != identify
fail 'Not the Same Objects!'
end
if other.to_sql != to_sql
<<-SQL.gsub(/^ {8}/, '')
#{drop}
#{other.to_sql}
SQL
end
end
|
#execute(sql) ⇒ Object
72
73
74
|
# File 'lib/dumbo/pg_object.rb', line 72
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
load_attributes
self
end
end
|
#identify ⇒ Object
19
20
21
|
# File 'lib/dumbo/pg_object.rb', line 19
def identify
identifier.map { |a| public_send a }
end
|
#load_attributes ⇒ Object
39
40
|
# File 'lib/dumbo/pg_object.rb', line 39
def load_attributes
end
|
#upgrade(other) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/dumbo/pg_object.rb', line 42
def upgrade(other)
return to_sql if other.nil?
if other.identify != identify
fail 'Not the Same Objects!'
end
if other.to_sql != to_sql
<<-SQL.gsub(/^ {8}/, '')
#{drop}
#{to_sql}
SQL
end
end
|