Class: PgMeta::Schema

Inherits:
Node
  • Object
show all
Defined in:
lib/pg_meta/meta.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#name, #parent, #root

Instance Method Summary collapse

Methods inherited from Node

#dump, #dump_value, #guid, #inspect, #sid, #to_s, #to_yaml, #uid

Constructor Details

#initialize(database, name, owner, hidden: false) ⇒ Schema

Returns a new instance of Schema.



136
137
138
139
140
141
142
143
144
# File 'lib/pg_meta/meta.rb', line 136

def initialize(database, name, owner, hidden: false)
  super(database, name)
  @owner = owner
  @tables = {}
  @functions = {}
  @procedures = {}
  @hidden = hidden
  database.schemas[name] = self
end

Instance Attribute Details

#functionsObject (readonly)

Hash of functions



131
132
133
# File 'lib/pg_meta/meta.rb', line 131

def functions
  @functions
end

#ownerObject (readonly)

Owner of the schema



122
123
124
# File 'lib/pg_meta/meta.rb', line 122

def owner
  @owner
end

#proceduresObject (readonly)

Hash of procedures



134
135
136
# File 'lib/pg_meta/meta.rb', line 134

def procedures
  @procedures
end

#tablesObject (readonly)

Hash of tables and views. TODO: Rename #relations



125
126
127
# File 'lib/pg_meta/meta.rb', line 125

def tables
  @tables
end

Instance Method Details

#[](sid) ⇒ Object

Lookup schema objects by sid



147
# File 'lib/pg_meta/meta.rb', line 147

def [](sid) = database["#{uid}.#{sid}"]

#hidden=(hide) ⇒ Object

Set hidden property



153
154
155
156
157
158
159
160
# File 'lib/pg_meta/meta.rb', line 153

def hidden=(hide)
  if @hidden
    database.schemas[name] = database.hidden_schemas.delete(name) if !hide
  else
    database.hidden_schemas[name] = database.schemas.delete(name) if hide
  end
  @hidden = hide
end

#hidden?Boolean

True if schema is hidden. This can be set dynamically

Returns:

  • (Boolean)


150
# File 'lib/pg_meta/meta.rb', line 150

def hidden?() @hidden end

#to_hObject



162
# File 'lib/pg_meta/meta.rb', line 162

def to_h() attrs_to_h(:name, :owner, :tables, :views, :functions, :procedures) end

#viewsObject

Hash of views



128
# File 'lib/pg_meta/meta.rb', line 128

def views() @views ||= @tables.select { |_, table| table.view? } end