Class: PgMeta::Node
- Inherits:
-
Object
- Object
- PgMeta::Node
- Defined in:
- lib/pg_meta/dump.rb,
lib/pg_meta/meta.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Unique name within parent context.
-
#parent ⇒ Object
readonly
Parent object.
-
#root ⇒ Object
readonly
Database object.
Instance Method Summary collapse
- #dump ⇒ Object
- #dump_value(v) ⇒ Object
-
#guid ⇒ Object
Unique id within a RDBMS.
-
#initialize(parent, name) ⇒ Node
constructor
A new instance of Node.
- #inspect ⇒ Object
-
#sid ⇒ Object
Unique id within a schema.
- #to_h ⇒ Object
- #to_s ⇒ Object
- #to_yaml ⇒ Object
-
#uid ⇒ Object
Unique id within a database.
Constructor Details
#initialize(parent, name) ⇒ Node
Returns a new instance of Node.
31 32 33 34 35 36 |
# File 'lib/pg_meta/meta.rb', line 31 def initialize(parent, name) @root = parent&.root || self @parent = parent @name = name parent && parent.root.send(:add_node, self) # Add object to global database lookup end |
Instance Attribute Details
#name ⇒ Object (readonly)
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”, eg. ‘func(integer)’
14 15 16 |
# File 'lib/pg_meta/meta.rb', line 14 def name @name end |
#parent ⇒ Object (readonly)
Parent object. nil for Database objects
9 10 11 |
# File 'lib/pg_meta/meta.rb', line 9 def parent @parent end |
#root ⇒ Object (readonly)
Database object. Equal to self for Database objects. TODO: Rename ‘database’
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
Unique id within a RDBMS
27 28 29 |
# File 'lib/pg_meta/meta.rb', line 27 def guid() @guid ||= [parent.guid, name].compact.join(".") end |
#inspect ⇒ Object
42 |
# File 'lib/pg_meta/meta.rb', line 42 def inspect() "#<#{self.class}:#{guid}>" end |
#sid ⇒ Object
Unique id within a schema. Only tables, columns, and functions have a sid
17 18 19 |
# File 'lib/pg_meta/meta.rb', line 17 def sid() @sid = nil end |
#to_h ⇒ Object
39 |
# File 'lib/pg_meta/meta.rb', line 39 def to_h = raise StandardError, "Undefined method" |
#to_s ⇒ Object
38 |
# File 'lib/pg_meta/meta.rb', line 38 def to_s = name.to_s |
#to_yaml ⇒ Object
40 |
# File 'lib/pg_meta/meta.rb', line 40 def to_yaml = to_h.to_yaml |
#uid ⇒ Object
Unique id within a database. The database object itself has a nil uid
22 23 24 |
# File 'lib/pg_meta/meta.rb', line 22 def uid() @uid ||= [parent.uid, name].compact.join(".") end |