Sha256: 72ae7470c20d96b63d9f629e0af35bdda3675a2d8a1749e347693fdc3ffa39c7

Contents?: true

Size: 925 Bytes

Versions: 2

Compression:

Stored size: 925 Bytes

Contents

# frozen_string_literal: true

module TableSaw
  module DependencyGraph
    class Context
      attr_reader :manifest

      def initialize(manifest)
        @manifest = manifest
      end

      def belongs_to
        foreign_key_relationships.belongs_to
      end

      # rubocop:disable Naming/PredicateName
      def has_many
        foreign_key_relationships.has_many
      end

      def has_many_mapping
        @has_many_mapping ||= manifest.tables.transform_values(&:has_many)
      end

      # rubocop:enable Naming/PredicateName

      def foreign_key_relationships
        @foreign_key_relationships ||= TableSaw::Queries::ForeignKeyRelationships.new
      end

      def tables_with_no_ids
        @tables_with_no_ids ||= TableSaw::Queries::NoIdTables.new.call
      end

      def perform_query(sql)
        TableSaw::Connection.with do |conn|
          conn.exec(sql)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
table_saw-0.5.0 lib/table_saw/dependency_graph/context.rb
table_saw-0.4.0 lib/table_saw/dependency_graph/context.rb