Enhancement for gem env

オープン
#9,883 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
ruby
領域
cli

調査の方向性

まず、提案されている show_environment の実装を読み、gem env を実行して現在の出力を YAML の例と比較します。一覧にある設定、ディレクトリ、gem パス、シェルパスの値がどのように組み立てられているかを確認します。出力形式について合意し、提案されている存在チェック、ホームディレクトリの墨消し、中央集約されたフォーマットを実装すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

The following rewrite of show_environment suggests improvements of gem env output.

Feedback on further improvements or alternative angles appreciated.

Feature Benefits
Outputs YAML (near already) Can parse, pipe to yq for colors, etc.
Checks file presence Helpful in bug reports
Replaces Dir.home with ~ Redaction / Privacy
Centralizes formatting DRY
Example output
RubyGems Environment:
  Version:
    - 4.0.20
  Platforms:
    - ruby
    - arm64-darwin-25
  Configuration:
    update_sources: true
    verbose: true
    backtrace: true
    bulk_threshold: 1000
    gem: --no-document
  Sources:
    - https://rubygems.org/
  Dependencies:
    Ruby version: 4.0.7 (2026-09-15 patchlevel 0) [arm64-darwin25]
    Ruby executable: /opt/homebrew/opt/ruby/bin/ruby
    Git executable: /usr/bin/git
  Directories:
    Global install: /opt/homebrew/lib/ruby/gems/4.0.0
    # Global config: /opt/homebrew/Cellar/ruby/4.0.7/etc
    Executable: /opt/homebrew/lib/ruby/gems/4.0.0/bin
    # User install: ~/.local/share/gem/ruby/4.0.0
    Spec cache: ~/.cache/gem/specs
    # Credentials: ~/.local/share/gem/credentials
  Gem path:
    - /opt/homebrew/lib/ruby/gems/4.0.0
    # - ~/.local/share/gem/ruby/4.0.0
    - /opt/homebrew/Cellar/ruby/4.0.7/lib/ruby/gems/4.0.0
  Shell path:
    - /opt/homebrew/bin
    - /opt/homebrew/sbin
    - /opt/homebrew/opt/ruby/bin
    - /usr/bin
    - /bin
    - /usr/sbin
    - /sbin
    - /opt/homebrew/lib/ruby/gems/4.0.0/bin
Code
  def exist(value)
    case value
    when %r{^/}
      File.stat(value)
    end
    ''
  rescue Errno::ENOENT
    '# '
  end

  def tree(items)
    items.flat_map do |group, items|
      items.compact.map do |item|
        item = [item].flatten
        line = exist(item.last) + (item.one? ? '- ' : '') + item.join(': ')
        line.prepend('    ').gsub(Dir.home, '~')
      end.prepend(format('  %s:', group))
    end
  end

  def show_environment # :nodoc:
    config = {}
    Gem.configuration.each do |name, value|
      config[name] = name == 'gemcutter_key' ? value.gsub(/./, '*') : value
    end
    {
      'Version' => [Gem::VERSION],
      'Platforms' => Gem.platforms.map(&:to_s),
      'Configuration' => config,
      'Sources' => Gem.sources.to_a,
      'Dependencies' => {
        'Ruby version' => "#{RUBY_VERSION} (#{RUBY_RELEASE_DATE} patchlevel #{RUBY_PATCHLEVEL}) [#{RUBY_PLATFORM}]",
        'Ruby executable' => Gem.ruby,
        'Git executable' => git_path
      },
      'Directories' => {
        'Global install' => Gem.dir,
        'Global config' => Gem::ConfigFile::SYSTEM_CONFIG_PATH,
        'Executable' => Gem.bindir,
        'User install' => Gem.user_dir,
        'Prefix' => Gem.prefix,
        'Spec cache' => Gem.spec_cache_dir,
        'Credentials' => Gem.configuration.credentials_path
      },
      'Gem path' => ([Gem.dir] + Gem.path).uniq,
      'Shell path' => ENV['PATH'].split(File::PATH_SEPARATOR)
    }.then { tree(it).prepend('RubyGems Environment:').join("\n") }
  end
主要言語
Ruby
スター
4k
フォーク
2k
平均マージ
1日 5時間
マージ済み PR(30日)
36

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ruby/rubygems のほかの issue

ruby/rubygems の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。