module Whiteprint::Migrator

Public Class Methods

eager_load!() click to toggle source
# File lib/whiteprint/migrator.rb, line 24
def eager_load!
  return unless Whiteprint.config.eager_load

  Rails.application.eager_load! if defined?(Rails)

  [*Whiteprint.config.eager_load_paths.uniq].each do |path|
    Gem.find_files(path).each do |file|
      load file
    end
  end
end
explanations() click to toggle source
# File lib/whiteprint/migrator.rb, line 36
def explanations
  Whiteprint.changed_whiteprints.map.with_index do |whiteprint, index|
    whiteprint.explanation(index + 1)
  end
end
interactive(input: $stdin, output: $stdout) click to toggle source
# File lib/whiteprint/migrator.rb, line 46
def interactive(input: $stdin, output: $stdout)
  eager_load!
  cli = Cli.new(input, output)

  # return if there are no changes
  cli.say('Whiteprint detected no changes') and return if no_changes?

  # list all changes
  cli.say "Whiteprint has detected <%= color('#{number_of_changes}', :bold, :white) %> changes to your models.", *explanations

  if Whiteprint.config.migration_strategy == :ask
    cli.choose do |menu|
      menu.header = 'Migrations'
      menu.prompt = 'How would you like to process these changes?'
      menu.choice('In one migration')       { Whiteprint.migrate cli, separately: false }
      menu.choice('In separate migrations') { Whiteprint.migrate cli, separately: true }
    end
  else
    Whiteprint.migrate cli, separately: (Whiteprint.config.migration_strategy == :separately)
  end
end
no_changes?() click to toggle source
# File lib/whiteprint/migrator.rb, line 42
def no_changes?
  number_of_changes == 0
end
number_of_changes() click to toggle source
# File lib/whiteprint/migrator.rb, line 68
def number_of_changes
  Whiteprint.changed_whiteprints.size
end