Class: PgMeta::Node
- Inherits:
-
Object
show all
- Defined in:
- lib/pg_meta/dump.rb,
lib/pg_meta/meta.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(parent, name) ⇒ Node
Returns a new instance of Node.
23
24
25
26
27
28
|
# File 'lib/pg_meta/meta.rb', line 23
def initialize(parent, name)
@root = parent&.root || self
@parent = parent
@name = name
parent && parent.root.send(:add_node, self)
end
|
Instance Attribute Details
#name ⇒ Object
Unique name within parent context. This is usually what we understand as the name of an object but functions have the full signature as “name”
13
14
15
|
# File 'lib/pg_meta/meta.rb', line 13
def name
@name
end
|
#parent ⇒ Object
Parent object. nil for Database objects
9
10
11
|
# File 'lib/pg_meta/meta.rb', line 9
def parent
@parent
end
|
#root ⇒ Object
Database object. Equal to self for Database objects
6
7
8
|
# File 'lib/pg_meta/meta.rb', line 6
def root
@root
end
|
Instance Method Details
#dump ⇒ Object
6
7
8
|
# File 'lib/pg_meta/dump.rb', line 6
def dump
dump_value(to_h)
end
|
#dump_value(v) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/pg_meta/dump.rb', line 10
def dump_value(v)
case v
when Hash
puts "{"
indent {
v.each { |k,v|
print "#{k}: "
dump_value(v)
}
}
puts "}"
when []
puts "[]"
when Array
puts "["
indent {
v.each { |v|
dump_value(v)
}
}
puts "]"
else
puts (v.nil? ? "nil" : v)
end
end
|
#guid ⇒ Object
19
20
21
|
# File 'lib/pg_meta/meta.rb', line 19
def guid()
@guid ||= [parent.guid, name].compact.join(".")
end
|
#inspect ⇒ Object
33
|
# File 'lib/pg_meta/meta.rb', line 33
def inspect() "#<#{self.class}:#{guid}>" end
|
#to_h ⇒ Object
30
|
# File 'lib/pg_meta/meta.rb', line 30
def to_h() raise StandardError, "Undefined method" end
|
#to_yaml ⇒ Object
31
|
# File 'lib/pg_meta/meta.rb', line 31
def to_yaml() to_h.to_yaml end
|
#uid ⇒ Object
15
16
17
|
# File 'lib/pg_meta/meta.rb', line 15
def uid()
@uid ||= [parent.uid, name].compact.join(".")
end
|