class DbAgent::TableOrderer

Attributes

handler[R]

Public Class Methods

new(handler) click to toggle source
# File lib/db_agent/table_orderer.rb, line 5
def initialize(handler)
  @handler = handler
end

Public Instance Methods

db() click to toggle source
# File lib/db_agent/table_orderer.rb, line 10
def db
  handler.sequel_db
end
dependencies(table) click to toggle source
# File lib/db_agent/table_orderer.rb, line 22
def dependencies(table)
  _dependencies(table, ds = {})
  ds
    .inject([]){|memo,(_,plus)| (memo + plus).uniq }
    .sort{|t1,t2| tsort.index(t1) - tsort.index(t2) }
    .reject{|x| x == table }
end
graph() click to toggle source
# File lib/db_agent/table_orderer.rb, line 18
def graph
  @graph ||= TSortComputation.new(db).graph
end
tsort() click to toggle source
# File lib/db_agent/table_orderer.rb, line 14
def tsort
  @tsort ||= TSortComputation.new(db).to_a
end

Private Instance Methods

_dependencies(table, ds) click to toggle source
# File lib/db_agent/table_orderer.rb, line 30
def _dependencies(table, ds)
  return ds if ds.has_key?(table)
  ds[table] = graph[table]
  ds[table].each do |child|
    _dependencies(child, ds)
  end
end