Class: RareMap::Mapper
- Inherits:
-
Object
- Object
- RareMap::Mapper
- Includes:
- ConfigLoader, ModelBuilder, ModelGenerator, RailsLocator, SchemaParser, SchemaReader
- Defined in:
- lib/rare_map.rb
Overview
RareMap::Mapper converts relational databases into ActiveRecord files.
Constant Summary
Constants included from ConfigLoader
Instance Method Summary collapse
-
#initialize ⇒ Mapper
constructor
Creates a Mapper.
-
#mapping ⇒ Object
Converts relational databases into ActiveRecord files by given RareMap config yaml file.
Methods included from RailsLocator
Methods included from ConfigLoader
Methods included from SchemaReader
Methods included from SchemaParser
Methods included from ModelBuilder
Methods included from ModelGenerator
Constructor Details
#initialize ⇒ Mapper
Creates a Mapper.
24 25 26 |
# File 'lib/rare_map.rb', line 24 def initialize @rails_root = locate_rails_root end |
Instance Method Details
#mapping ⇒ Object
Converts relational databases into ActiveRecord files by given RareMap config yaml file.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rare_map.rb', line 29 def mapping @db_profiles = load_config @rails_root ? File.join(@rails_root, 'config') : '.' @db_profiles.each do |profile| profile.schema = read_schema profile profile.tables = parse_schema profile.schema end @models = build_models @db_profiles generate_models @models, @rails_root if @rails_root puts '*****************************************************************' puts ' Activerecord models are generated. Enjoy it!' puts '*****************************************************************' else puts '*****************************************************************' puts ' A demo.rb is generated.' puts '*****************************************************************' generate_demo unless File.exist?('demo.rb') end @models rescue ConfigNotFoundError => e puts "Please put your database config in `#{'config/' if @rails_root}rare_map.yml`." end |