Rubygems のソース

参考:

rubygems/rubygems: Library packaging and distribution for Ruby – GitHub

Documentation for rubygems/rubygems | RubyDoc.info

find_by_name

参考:

Method: Gem::Specification.find_by_name — Documentation for rubygems/rubygems | RubyDoc.info

Gem::Resolver

複数の gem のバージョン要件を与えて依存関係を解決する。

def dep(name, version = nil)
  Gem::Dependency.new(
    name,
    Gem::Requirement.create(version)
  )
end

deps = [
  dep("rails", "6.0.0.beta1"),
  dep("webpacker", ">= 4.0.x"),
  dep("sqlite3", ">= 1.4.0")
]

puts Gem::Resolver.new(deps).resolve

参考:

Class: Gem::Resolver — Documentation for rubygems/rubygems | RubyDoc.info

Method: Gem::Resolver#resolve — Documentation for rubygems/rubygems | RubyDoc.info

Gem::Resolver::BestSet

バージョン要件に合う gem をリモートを含めて探す。

require "rubygems/remote_fetcher"

gem_name = "bundler"
version  = "~> 2.0"

set = Gem::Resolver::BestSet.new 

requirement = Gem::Requirement.create(version)

dependency = Gem::Dependency.new(
  gem_name,
  requirement
)

request = Gem::Resolver::DependencyRequest.new(
  dependency,
  nil
)

p set.find_all(request).map { |gem| gem.version.to_s }

参考:

Class: Gem::Resolver::BestSet — Documentation for rubygems/rubygems | RubyDoc.info

rubygems/best_set.rb at v3.0.2 · rubygems/rubygems

Gem::Version

参考:

Class: Gem::Version — Documentation for rubygems/rubygems | RubyDoc.info

Gem::Requirement

参考:

class Gem::Requirement (Ruby 2.6.0)

Class: Gem::Requirement — Documentation for rubygems/rubygems | RubyDoc.info

Gem::Dependency

参考:

Class: Gem::Dependency — Documentation for rubygems/rubygems | RubyDoc.info

Gem::Resolver::DependencyRequest

参考:

Class: Gem::Resolver::DependencyRequest — Documentation for rubygems/rubygems | RubyDoc.info

install

参考:

install – rubygems/installer.rb at v3.0.3 · rubygems/rubygems – GitHub

write_spec

参考:

write_spec – rubygems/installer.rb at v3.0.3 · rubygems/rubygems – GitHub

Gem::Source

参考:

rubygems/source.rb at v3.0.3 · rubygems/rubygems – GitHub

Gem::RemoteFetcher

参考:

rubygems/remote_fetcher.rb at v3.0.3 · rubygems/rubygems – GitHub

Gem::SpecFetcher

参考:

rubygems/spec_fetcher.rb at v3.0.3 · rubygems/rubygems – GitHub

gem fetch コマンド

パックされたままの gem を取得する。

参考:

rubygems/fetch_command.rb at v3.0.3 · rubygems/rubygems – GitHub

テスト

TestGemResolverBestSet

参考:

rubygems/test_gem_resolver_best_set.rb at v3.0.2 · rubygems/rubygems – GitHub

TestGemResolver

参考:

rubygems/test_gem_resolver.rb at v3.0.2 · rubygems/rubygems – GitHub

Gem::TestCase

参考:

rubygems/test_case.rb at v3.0.2 · rubygems/rubygems – GitHub

記事をシェアする:
タグ:

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

Protected by reCAPTCHA