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) ⇒ Migrator

Returns a new instance of Migrator.



4
5
6
7
# File 'lib/migrator.rb', line 4

def initialize(repo: raise, shell: raise)
  @shell = shell
  @repo = repo
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



16
17
18
19
# File 'lib/migrator.rb', line 16

def directories_to_migrate
  migrate_dirs = repo.files_changed.select {|f| f.match("/migrate/") }.map {|f| File.dirname(f) }.uniq
  migrate_dirs.select {|d| in_rack_application?(d) };
end

#migrate_where_necessaryObject



9
10
11
12
13
14
# File 'lib/migrator.rb', line 9

def migrate_where_necessary
  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