class GemLookup::Help

Constants

OUTPUT_OPTION_SPACING

@return [Numeric] the spacing for output options

Public Class Methods

display(exit_code: nil) click to toggle source

Outputs the generated content. @param exit_code [Numeric, nil] the exit code (if any) to exit with.

# File lib/gem_lookup/help.rb, line 11
def display(exit_code: nil)
  puts documentation

  exit exit_code unless exit_code.nil?
end
documentation() click to toggle source

Generates the help documentation. @return [String] the help documentation.

# File lib/gem_lookup/help.rb, line 27
      def documentation
        <<~HELP

          Usage: gems [OPTIONS] GEMS

            Retrieves gem-related information from https://rubygems.org

          Example: gems -j rails rspec

          This application's purpose is to make working with with RubyGems.org easier. 💖
          It uses the RubyGems public API to perform lookups, and parses the JSON response
          body to provide details about the most recent version, as well as links to
          the home page, source code, changelog, and mailing list.

          Feel free to pass in as many gems that you like, as it makes requests in
          parallel. There is a rate limit, #{RateLimit.number}/sec. If it detects the amount of gems it
          has been passed is more than the rate limit, the application will run in Batch
          mode, and introduce a one second delay between batch lookups.

          #{options}

          Rate limit documentation: #{RateLimit.documentation_url}
        HELP
      end
version(exit_code: nil) click to toggle source

Outputs the gem name and current gem version. @param exit_code [Numeric, nil] the exit code (if any) to exit with.

# File lib/gem_lookup/help.rb, line 19
def version(exit_code: nil)
  puts "#{NAME} #{VERSION}"

  exit exit_code unless exit_code.nil?
end

Private Class Methods

flag_output() click to toggle source

rubocop:disable Metrics/AbcSize Generates a formatted string that displays the supported flag details. @return [String] the supported flags and their details.

# File lib/gem_lookup/help.rb, line 66
def flag_output
  [].tap do |output|
    Flags.supported.keys.sort.each do |key|
      matches = Flags.supported[key][:matches].join ' '
      spaces = ' ' * (OUTPUT_OPTION_SPACING - matches.length)
      output.push "  #{matches}#{spaces}#{Flags.supported[key][:desc]}"
    end
  end.join "\n"
end
options() click to toggle source

Generates an Output Options string that includes the supported flag details. @return [String] the supported output options.

# File lib/gem_lookup/help.rb, line 56
      def options
        <<~OPTIONS.chomp
          Output Options:
          #{flag_output}
        OPTIONS
      end