Class: Gemdiff::CLI

Inherits:
Thor
  • Object
show all
Includes:
Colorize, Thor::Actions
Defined in:
lib/gemdiff/cli.rb

Constant Summary collapse

CHECKING_FOR_OUTDATED =
"Checking for outdated gems in your bundle..."
NOTHING_TO_UPDATE =
"Nothing to update."
WORKING_DIRECTORY_IS_NOT_CLEAN =
"Your working directory is not clean. Please commit or stash before updating."

Constants included from Colorize

Gemdiff::Colorize::COLORS

Instance Method Summary collapse

Methods included from Colorize

#colorize, #colorize_git_output

Instance Method Details

#compare(gem_name, old_version = nil, new_version = nil) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/gemdiff/cli.rb', line 48

def compare(gem_name, old_version = nil, new_version = nil)
  gem = find(gem_name)
  return unless gem.repo?
  gem.set_versions old_version, new_version
  if gem.missing_versions?
    puts CHECKING_FOR_OUTDATED
    unless gem.load_bundle_versions
      puts "#{gem_name} is not outdated in your bundle. Specify versions."
      return
    end
  end
  puts gem.compare_message
  gem.compare
end

#find(gem_name) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/gemdiff/cli.rb', line 15

def find(gem_name)
  gem = OutdatedGem.new(gem_name)
  if gem.repo?
    puts gem.repo
  else
    puts "Could not find github repository for #{gem_name}."
  end
  gem
end

#master(gem_name) ⇒ Object



38
39
40
41
# File 'lib/gemdiff/cli.rb', line 38

def master(gem_name)
  gem = find(gem_name)
  gem.master
end

#open(gem_name) ⇒ Object



26
27
28
29
# File 'lib/gemdiff/cli.rb', line 26

def open(gem_name)
  gem = find(gem_name)
  gem.open
end

#outdatedObject



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/gemdiff/cli.rb', line 64

def outdated
  puts CHECKING_FOR_OUTDATED
  inspector = BundleInspector.new
  puts inspector.outdated
  inspector.list.each do |gem|
    puts gem.compare_message
    response = ask("Open? (y to open, x to exit, else skip)")
    gem.compare if response == 'y'
    return if response == 'x'
  end
end

#releases(gem_name) ⇒ Object



32
33
34
35
# File 'lib/gemdiff/cli.rb', line 32

def releases(gem_name)
  gem = find(gem_name)
  gem.releases
end

#update(name) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/gemdiff/cli.rb', line 77

def update(name)
  gem = GemUpdater.new(name)
  unless gem.clean?
    puts WORKING_DIRECTORY_IS_NOT_CLEAN
  end
  puts "Updating #{name}..."
  gem.update
  diff_output = colorize_git_output(gem.diff)
  puts diff_output
  if diff_output.empty?
    puts NOTHING_TO_UPDATE
    return
  end
  response = ask("\nCommit? (c to commit, r to reset, else do nothing)")
  if response == 'c'
    gem.commit
    puts "\n" + colorize_git_output(gem.show)
  elsif response == 'r'
    puts gem.reset
  end
end