Class: TableSaw::Associations

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manifest) ⇒ Associations

Returns a new instance of Associations.



7
8
9
# File 'lib/table_saw/associations.rb', line 7

def initialize(manifest)
  @manifest = manifest
end

Instance Attribute Details

#manifestObject (readonly)

Returns the value of attribute manifest.



5
6
7
# File 'lib/table_saw/associations.rb', line 5

def manifest
  @manifest
end

Instance Method Details

#belongs_toObject



11
12
13
14
15
# File 'lib/table_saw/associations.rb', line 11

def belongs_to
  @belongs_to ||= foreign_keys.each_with_object(Hash.new { |h, k| h[k] = Set.new }) do |fk, memo|
    memo[fk.from_table].add(fk)
  end
end

#has_manyObject



17
18
19
20
21
# File 'lib/table_saw/associations.rb', line 17

def has_many
  @has_many ||= foreign_keys.each_with_object(Hash.new { |h, k| h[k] = Set.new }) do |fk, memo|
    memo[fk.to_table].add(fk)
  end
end