Sha256: c016a7c34e97729b39a77b073972cc5d182df2c7d9a8dbd74fb6c9b0cbd1c104
Contents?: true
Size: 1.22 KB
Versions: 2
Compression:
Stored size: 1.22 KB
Contents
# frozen_string_literal: true module TableSaw module DependencyGraph class Build attr_reader :manifest, :records def initialize(manifest) @manifest = manifest @records = {} end 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?) end records end private def add(directive) return [] unless directive.queryable? directives(directive).select(&:queryable?).each(&method(:add)) end 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 def select_ids(table) return [] unless table.partial? TableSaw::Connection.exec(table.query).map { |row| row[TableSaw.information_schema.primary_keys[table.name]] } end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
table_saw-1.0.1 | lib/table_saw/dependency_graph/build.rb |
table_saw-1.0.0 | lib/table_saw/dependency_graph/build.rb |