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
:reek:FeatureEnvy :reek:TooManyStatements.
- .print_gems(gems) ⇒ Object
-
.process_gem(name, method) ⇒ Object
:reek:TooManyStatements.
Class Method Details
.inspect_gem(specification, method) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/gemsmith/helpers/cli.rb', line 35 def inspect_gem specification, method return unless specification Gem::Inspector.new.public_send method, Gem::Specification.new(specification.spec_file) rescue Versionaire::Errors::Conversion => error say_status :error, error., :red end |
.pick_gem(gems, name) ⇒ Object
:reek:FeatureEnvy :reek:TooManyStatements
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/gemsmith/helpers/cli.rb', line 21 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 say_status :error, "Invalid option: #{answer}", :red 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
:reek:TooManyStatements
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/gemsmith/helpers/cli.rb', line 43 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 say_status(:error, "Unable to find gem: #{name}.", :red) and "" end end |