Sha256: df583c0c6531daa0cd5bc012f957d02b0a279283b7a1c7fc88880697dadcaa75

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module Gemsmith
  # Command Line Interface (CLI) helpers for the CLI class.
  module CLIHelpers
    def gem_name
      configuration.gem_name
    end

    def gem_class
      configuration.gem_class
    end

    def rails_version
      configuration.rails_version
    end

    module_function

    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

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

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

    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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gemsmith-7.2.0 lib/gemsmith/cli_helpers.rb
gemsmith-7.1.0 lib/gemsmith/cli_helpers.rb
gemsmith-7.0.0 lib/gemsmith/cli_helpers.rb