Module: Loader

Included in:
Exporter
Defined in:
lib/loader.rb

Instance Method Summary collapse

Instance Method Details

#join_tables_from_databaseObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/loader.rb', line 20

def join_tables_from_database
  join_tables = []
  excluded_tables = ["schema_migrations"]
  ActiveRecord::Base.connection.tables.each do |table| 
    unless ActiveRecord::Base.connection.columns(table).map { |c| c.name }.include?("id")
      join_tables << table unless excluded_tables.include?(table)
    end
  end
  join_tables.compact
end

#models_from_databaseObject

In most cases singularizing a table’s name yields the model’s name but in special cases where the model’s name is already seen as plural by rails, it expects the table’s name to then also be plural (so the model: ‘MyData’ goes with the table: ‘my_data’)



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/loader.rb', line 6

def models_from_database
  tables = ActiveRecord::Base.connection.tables
  tables.delete "config"
  if ENV['SKIP']
    table_names = ENV['SKIP'].split(',')
    table_names.each do |table_to_skip|
      puts "Skipping #{table_to_skip}"
      tables.delete table_to_skip.strip
    end
  end
  models = tables.collect { |table| table.camelize.singularize.constantize rescue nil || table.camelize.constantize rescue nil }.compact
  models << Radiant::Config
end