Class: OnlineMigrations::ForeignKeysCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/online_migrations/foreign_keys_collector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeForeignKeysCollector

Returns a new instance of ForeignKeysCollector.



8
9
10
# File 'lib/online_migrations/foreign_keys_collector.rb', line 8

def initialize
  @referenced_tables = Set.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missingObject



29
30
31
# File 'lib/online_migrations/foreign_keys_collector.rb', line 29

def method_missing(*)
  # we only care about foreign keys related methods
end

Instance Attribute Details

#referenced_tablesObject (readonly)

Returns the value of attribute referenced_tables.



6
7
8
# File 'lib/online_migrations/foreign_keys_collector.rb', line 6

def referenced_tables
  @referenced_tables
end

Instance Method Details

#collect {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



12
13
14
# File 'lib/online_migrations/foreign_keys_collector.rb', line 12

def collect
  yield self
end

#foreign_key(to_table, **_options) ⇒ Object



16
17
18
# File 'lib/online_migrations/foreign_keys_collector.rb', line 16

def foreign_key(to_table, **_options)
  @referenced_tables << to_table.to_s
end

#references(*ref_names, **options) ⇒ Object Also known as: belongs_to



20
21
22
23
24
25
26
# File 'lib/online_migrations/foreign_keys_collector.rb', line 20

def references(*ref_names, **options)
  if options[:foreign_key]
    ref_names.each do |ref_name|
      @referenced_tables << Utils.foreign_table_name(ref_name, options)
    end
  end
end