class TableSaw::DependencyGraph::Build

Attributes

manifest[R]
records[R]

Public Class Methods

new(manifest) click to toggle source
# File lib/table_saw/dependency_graph/build.rb, line 8
def initialize(manifest)
  @manifest = manifest
  @records = {}
end

Public Instance Methods

call() click to toggle source
# File lib/table_saw/dependency_graph/build.rb, line 13
def call
  manifest.tables.values.sort_by { |t| t.partial? ? 1 : 0 }.each do |table|
    add TableSaw::DependencyGraph::AddDirective.new(table.name, ids: select_ids(table), partial: table.partial?,
                                                                has_many: table.has_many)
  end

  records
end

Private Instance Methods

add(directive) click to toggle source
# File lib/table_saw/dependency_graph/build.rb, line 24
def add(directive)
  return [] unless directive.queryable?

  directives(directive).select(&:queryable?).each(&method(:add))
end
directives(dir) click to toggle source
# File lib/table_saw/dependency_graph/build.rb, line 30
def directives(dir)
  record = records[dir.table_name]

  if record
    dir.partial? ? record.fetch_associations(dir) : []
  else
    TableSaw::DependencyGraph::DumpTable.new(manifest: manifest, name: dir.table_name, partial: dir.partial?)
      .tap { |table| records[dir.table_name] = table }.fetch_associations(dir)
  end
end
select_ids(table) click to toggle source
# File lib/table_saw/dependency_graph/build.rb, line 41
def select_ids(table)
  return [] unless table.partial?

  TableSaw::Connection.exec(table.query).map { |row| row[TableSaw.schema_cache.primary_keys(table.name)] }
end