Class: PgGraph::Data::Schema

Inherits:
DatabaseObject show all
Defined in:
lib/pg_graph/data/data.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#dimension, #type

Instance Method Summary collapse

Methods inherited from DatabaseObject

#<=>, #dot, #guid, #name, #uid

Methods inherited from Node

#inspect, #object, #value, #value_type

Constructor Details

#initialize(database, type) ⇒ Schema

Returns a new instance of Schema.



192
193
194
195
196
197
198
199
# File 'lib/pg_graph/data/data.rb', line 192

def initialize(database, type)
  constrain database, Database
  constrain type, PgGraph::Type::Schema
  @database = database
  super(type)
  @impl = {} # A hash from table name to Table object
  type.tables.each { |table| @impl[table.name] = Table.new(self, table) }
end

Instance Attribute Details

#databaseObject (readonly)

Returns the value of attribute database.



187
188
189
# File 'lib/pg_graph/data/data.rb', line 187

def database
  @database
end

Instance Method Details

#dataObject Also known as: to_h

Return schema as a hash from table name to table hash



208
# File 'lib/pg_graph/data/data.rb', line 208

def data() @impl.map { |k,v| [k, v.data] }.to_h end

#each(&block) ⇒ Object

Iterate tables



205
# File 'lib/pg_graph/data/data.rb', line 205

def each(&block) tables.each { |table| yield table } end

#tablesObject

List of Table objects



190
# File 'lib/pg_graph/data/data.rb', line 190

def tables() @impl.values end

#to_yamlObject

end



214
# File 'lib/pg_graph/data/data.rb', line 214

def to_yaml() @impl.map { |k,v| [k, v.to_yaml] }.to_h end