Class: Migrator
- Inherits:
-
Object
- Object
- Migrator
- Defined in:
- lib/sfb_scripts/migrations/migrator.rb
Instance Attribute Summary collapse
-
#folder_guard ⇒ Object
Returns the value of attribute folder_guard.
-
#queue ⇒ Object
Returns the value of attribute queue.
-
#repo ⇒ Object
Returns the value of attribute repo.
-
#shell ⇒ Object
Returns the value of attribute shell.
Instance Method Summary collapse
- #directories_to_migrate ⇒ Object
-
#initialize(repo: raise, shell: raise, queue: raise, folder_guard: raise) ⇒ Migrator
constructor
A new instance of Migrator.
- #migrate_where_necessary ⇒ Object
Constructor Details
#initialize(repo: raise, shell: raise, queue: raise, folder_guard: raise) ⇒ Migrator
Returns a new instance of Migrator.
4 5 6 7 8 9 |
# File 'lib/sfb_scripts/migrations/migrator.rb', line 4 def initialize(repo: raise, shell: raise, queue: raise, folder_guard: raise) @shell = shell @repo = repo @queue = queue @folder_guard = folder_guard end |
Instance Attribute Details
#folder_guard ⇒ Object
Returns the value of attribute folder_guard.
2 3 4 |
# File 'lib/sfb_scripts/migrations/migrator.rb', line 2 def folder_guard @folder_guard end |
#queue ⇒ Object
Returns the value of attribute queue.
2 3 4 |
# File 'lib/sfb_scripts/migrations/migrator.rb', line 2 def queue @queue end |
#repo ⇒ Object
Returns the value of attribute repo.
2 3 4 |
# File 'lib/sfb_scripts/migrations/migrator.rb', line 2 def repo @repo end |
#shell ⇒ Object
Returns the value of attribute shell.
2 3 4 |
# File 'lib/sfb_scripts/migrations/migrator.rb', line 2 def shell @shell end |
Instance Method Details
#directories_to_migrate ⇒ Object
21 22 23 24 |
# File 'lib/sfb_scripts/migrations/migrator.rb', line 21 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| folder_guard.allowed?(d) }; end |
#migrate_where_necessary ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/sfb_scripts/migrations/migrator.rb', line 11 def migrate_where_necessary shell.notify "\nMigrating:" migrations.each do |migration| queue.enqueue_b do shell.run "RAILS_ENV=#{migration[:env]} bundle exec rake db:create db:migrate", dir: migration[:dir] end end queue.join end |