Module: Gemsmith::CLIHelpers

Included in:
CLI
Defined in:
lib/gemsmith/cli_helpers.rb

Overview

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.pick_gem(gems, name) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/gemsmith/cli_helpers.rb', line 24

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

  if (1..gems.size).include?(answer.to_i)
    spec_aid.find name, gems[answer.to_i - 1].version.version
  else
    error "Invalid option: #{answer}"
  end
end


18
19
20
21
22
# File 'lib/gemsmith/cli_helpers.rb', line 18

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



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

def process_gem name, method
  specs = spec_aid.find_all name

  case
    when specs.size == 1
      spec_aid.send method, specs.first
    when specs.size > 1
      print_gems specs
      spec_aid.send method, pick_gem(specs, name)
    else
      error "Unable to find gem: #{name}."
  end
end

Instance Method Details

#gem_classObject



8
9
10
# File 'lib/gemsmith/cli_helpers.rb', line 8

def gem_class
  configuration.gem_class
end

#gem_nameObject



4
5
6
# File 'lib/gemsmith/cli_helpers.rb', line 4

def gem_name
  configuration.gem_name
end

#rails_versionObject



12
13
14
# File 'lib/gemsmith/cli_helpers.rb', line 12

def rails_version
  configuration.rails_version
end