Class: DbAgent::TableOrderer

Inherits:
Object
  • Object
show all
Defined in:
lib/db_agent/table_orderer.rb

Defined Under Namespace

Classes: TSortComputation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(handler) ⇒ TableOrderer



5
6
7
# File 'lib/db_agent/table_orderer.rb', line 5

def initialize(handler)
  @handler = handler
end

Instance Attribute Details

#handlerObject (readonly)

Returns the value of attribute handler.



8
9
10
# File 'lib/db_agent/table_orderer.rb', line 8

def handler
  @handler
end

Instance Method Details

#dbObject



10
11
12
# File 'lib/db_agent/table_orderer.rb', line 10

def db
  handler.sequel_db
end

#dependencies(table) ⇒ Object



22
23
24
25
26
27
28
# 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

#graphObject



18
19
20
# File 'lib/db_agent/table_orderer.rb', line 18

def graph
  @graph ||= TSortComputation.new(db).graph
end

#tsortObject



14
15
16
# File 'lib/db_agent/table_orderer.rb', line 14

def tsort
  @tsort ||= TSortComputation.new(db).to_a
end