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
- .inspect_gem(specification, method) ⇒ Object
- .pick_gem(gems, name) ⇒ Object
- .print_gems(gems) ⇒ Object
- .process_gem(name, method) ⇒ Object
Class Method Details
.inspect_gem(specification, method) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/gemsmith/helpers/cli.rb', line 33 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.) end |
.pick_gem(gems, name) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/gemsmith/helpers/cli.rb', line 19 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 |
.print_gems(gems) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/gemsmith/helpers/cli.rb', line 9 def print_gems gems say "Multiple versions found:\n\n" gems.each.with_index do |spec, index| say "#{index + 1}. #{spec.name} #{spec.version.version}" end say "q. Quit.\n\n" end |
.process_gem(name, method) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/gemsmith/helpers/cli.rb', line 40 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 |