Module: Gemsmith::Helpers::CLI

Included in:
CLI
Defined in:
lib/gemsmith/helpers/cli.rb

Overview

Command Line Interface (CLI) helpers for the CLI class.

Class Method Summary collapse

Class Method Details

.inspect_gem(specification, method) ⇒ Object



29
30
31
32
33
34
# File 'lib/gemsmith/helpers/cli.rb', line 29

def inspect_gem specification, method
  return unless specification
  Gem::Inspector.new.public_send method, Gem::Specification.new(specification.spec_file)
rescue Versionaire::Errors::Conversion => exception
  error(exception.message)
end

.pick_gem(gems, name) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gemsmith/helpers/cli.rb', line 15

def pick_gem gems, name
  answer = ask "Enter selection:"
  return if answer == "q"

  answer = answer.to_i

  if (1..gems.size).cover?(answer)
    Gem::Specification.find name, gems[answer - 1].version.version
  else
    error "Invalid option: #{answer}"
    nil
  end
end


9
10
11
12
13
# File 'lib/gemsmith/helpers/cli.rb', line 9

def print_gems gems
  say "Multiple versions found:\n\n"
  gems.each.with_index { |spec, index| say "#{index + 1}. #{spec.name} #{spec.version.version}" }
  say "q. Quit.\n\n"
end

.process_gem(name, method) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/gemsmith/helpers/cli.rb', line 36

def process_gem name, method
  specs = Gem::Specification.find_all name
  spec_count = specs.size

  if spec_count == 1
    inspect_gem specs.first, method
  elsif spec_count > 1
    print_gems specs
    inspect_gem pick_gem(specs, name), method
  else
    error("Unable to find gem: #{name}.") and ""
  end
end