class DbAgent::TableOrderer::TSortComputation
Attributes
db[R]
except[R]
Public Class Methods
new(db, except = [])
click to toggle source
# File lib/db_agent/table_orderer.rb, line 42 def initialize(db, except = []) @db = db @except = except end
Public Instance Methods
graph()
click to toggle source
# File lib/db_agent/table_orderer.rb, line 48 def graph g = Hash.new{|h,k| h[k] = [] } tsort_each_node.each do |table| tsort_each_child(table) do |child| g[child] << table end end g rescue TSort::Cyclic raise unless killed = to_kill TSortComputation.new(db, except + [killed]).graph end
to_a()
click to toggle source
# File lib/db_agent/table_orderer.rb, line 61 def to_a tsort.to_a rescue TSort::Cyclic raise unless killed = to_kill TSortComputation.new(db, except + [killed]).to_a end
tsort_each_child(table, &bl)
click to toggle source
# File lib/db_agent/table_orderer.rb, line 72 def tsort_each_child(table, &bl) db.foreign_key_list(table) .map{|fk| fk[:table] } .reject{|t| except.any?{|killed| killed.first == table && killed.last == t } } .each(&bl) end
tsort_each_node(&bl)
click to toggle source
# File lib/db_agent/table_orderer.rb, line 68 def tsort_each_node(&bl) db.tables.each(&bl) end
Private Instance Methods
to_kill()
click to toggle source
# File lib/db_agent/table_orderer.rb, line 83 def to_kill each_strongly_connected_component .select{|scc| scc.size > 1 } .sort_by{|scc| scc.size } .first end