Module: RareMap::ModelBuilder

Included in:
Mapper
Defined in:
lib/rare_map/model_builder.rb

Overview

RareMap::ModelBuilder converts an Array of DatabaseProfile into an Array of Model.

Instance Method Summary collapse

Instance Method Details

#build_models(db_profiles) ⇒ Array

Creaetes an Array of Model by given DatabaseProfile(s).

Returns:

  • (Array)

    an Array of Model



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rare_map/model_builder.rb', line 12

def build_models(db_profiles)
  models = []
  
  db_profiles.each do |db_prof|
    db_prof.tables.each do |table|
      opts = db_prof.options
      set_primary_key_by_options(table, opts)
      set_foreign_keys_by_options(table, opts)
      set_fk_suffix_by_options(table, opts)
      if opts.group?
        models << Model.new(db_prof.name, db_prof.connection, table, opts.group)
      else
        models << Model.new(db_prof.name, db_prof.connection, table)
      end
    end
  end
  
  build_relations models
  
  models
end