Class: Migrator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo: raise, shell: raise, migrate_engines: raise) ⇒ Migrator

hack: move engines flag into another object that decides



6
7
8
9
10
# File 'lib/migrator.rb', line 6

def initialize(repo: raise, shell: raise, migrate_engines: raise)
  @shell = shell
  @repo = repo
  @migrate_engines = migrate_engines
end

Instance Attribute Details

#repoObject

Returns the value of attribute repo.



2
3
4
# File 'lib/migrator.rb', line 2

def repo
  @repo
end

#shellObject

Returns the value of attribute shell.



2
3
4
# File 'lib/migrator.rb', line 2

def shell
  @shell
end

Instance Method Details

#directories_to_migrateObject



20
21
22
23
# File 'lib/migrator.rb', line 20

def directories_to_migrate
  migrate_dirs = repo.files_changed.select {|f| f.match("/migrate/") }.map {|f| File.dirname(f) }.map {|dir| dir.gsub(/\/db\/migrate$/, '')}.uniq
  migrate_dirs.select {|d| in_rack_application?(d) };
end

#migrate_where_necessaryObject



12
13
14
15
16
17
18
# File 'lib/migrator.rb', line 12

def migrate_where_necessary
  shell.notify "\nMigrating:"
  directories_to_migrate.each do |dir|
    shell.run "bundle exec rake db:migrate", dir: dir
    shell.run "RAILS_ENV=test bundle exec rake db:migrate", dir: dir
  end
end