Method: Migr8::RepositoryOperation#inspect

Defined in:
lib/migr8.rb

#inspect(n = 5) ⇒ Object



380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
# File 'lib/migr8.rb', line 380

def inspect(n=5)
  mig_hist, mig_dict = _get_migrations_hist_and_applied()
  pos = mig_hist.length - n - 1
  i = mig_hist.index {|mig| ! mig.applied? }  # index of oldest unapplied
  j = mig_hist.rindex {|mig| mig.applied? }   # index of newest applied
  start = i.nil? ? pos : [i - 1, pos].min
  start = 0 if start < 0
  if mig_hist.empty?
    status = "no migrations"
    recent = nil
  elsif i.nil?
    status = "all applied"
    recent = mig_hist[start..-1]
  elsif j.nil?
    status = "nothing applied"
    recent = mig_hist[0..-1]
  elsif i < j
    status = "YOU MUST APPLY #{mig_hist[i].version} AT FIRST!"
    recent = mig_hist[start..-1]
  else
    count = mig_hist.length - i
    status = "there are #{count} migrations to apply"
    status = "there is a migration to apply" if count == 1
    recent = mig_hist[start..-1]
  end
  missing = mig_dict.empty? ? nil : mig_dict.values
  return {:status=>status, :recent=>recent, :missing=>missing}
end