Class: TableSaw::DependencyGraph::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/table_saw/dependency_graph/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manifest) ⇒ Context

Returns a new instance of Context.



8
9
10
# File 'lib/table_saw/dependency_graph/context.rb', line 8

def initialize(manifest)
  @manifest = manifest
end

Instance Attribute Details

#manifestObject (readonly)

Returns the value of attribute manifest.



6
7
8
# File 'lib/table_saw/dependency_graph/context.rb', line 6

def manifest
  @manifest
end

Instance Method Details

#belongs_toObject



12
13
14
# File 'lib/table_saw/dependency_graph/context.rb', line 12

def belongs_to
  foreign_key_relationships.belongs_to
end

#foreign_key_relationshipsObject

rubocop:enable Naming/PredicateName



27
28
29
# File 'lib/table_saw/dependency_graph/context.rb', line 27

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

#has_manyObject

rubocop:disable Naming/PredicateName



17
18
19
# File 'lib/table_saw/dependency_graph/context.rb', line 17

def has_many
  foreign_key_relationships.has_many
end

#has_many_mappingObject



21
22
23
# File 'lib/table_saw/dependency_graph/context.rb', line 21

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

#perform_query(sql) ⇒ Object



35
36
37
38
39
# File 'lib/table_saw/dependency_graph/context.rb', line 35

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

#tables_with_no_idsObject



31
32
33
# File 'lib/table_saw/dependency_graph/context.rb', line 31

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