Module: Whiteprint::Migrator
- Defined in:
- lib/whiteprint/migrator.rb
Defined Under Namespace
Classes: Cli
Class Method Summary collapse
- .eager_load! ⇒ Object
- .explanations ⇒ Object
- .interactive(input: $stdin, output: $stdout) ⇒ Object
- .no_changes? ⇒ Boolean
- .number_of_changes ⇒ Object
Class Method Details
.eager_load! ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# 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 ⇒ Object
36 37 38 39 40 |
# 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) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# 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 || .header = 'Migrations' .prompt = 'How would you like to process these changes?' .choice('In one migration') { Whiteprint.migrate cli, separately: false } .choice('In separate migrations') { Whiteprint.migrate cli, separately: true } end else Whiteprint.migrate cli, separately: (Whiteprint.config.migration_strategy == :separately) end end |
.no_changes? ⇒ Boolean
42 43 44 |
# File 'lib/whiteprint/migrator.rb', line 42 def no_changes? number_of_changes == 0 end |
.number_of_changes ⇒ Object
68 69 70 |
# File 'lib/whiteprint/migrator.rb', line 68 def number_of_changes Whiteprint.changed_whiteprints.size end |