Sha256: 9a6c61497461629f391d2bbad44123f3a88bb1bc4f597659c3171922e151e533

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

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).include?(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

1 entries across 1 versions & 1 rubygems

Version Path
gemsmith-6.0.0 lib/gemsmith/cli_helpers.rb