Class: GemContribute::Resolver

Inherits:
Object
  • Object
show all
Defined in:
lib/gem_contribute/resolver.rb

Overview

Resolves a LockedGem to a Project (host + owner + repo) by querying the RubyGems v1 API and walking the metadata URIs in preference order.

Preference order (ADR-0003):

bug_tracker_uri    source_code_uri    homepage_uri

Recognized hosts: github.com, gitlab.com, codeberg.org. Anything else (mailing-list bug tracker, internal bugzilla, etc.) is stored as the ‘:source_url` in metadata so the user can at least see it.

Constant Summary collapse

API_BASE =
"https://rubygems.org/api/v1/gems"
KNOWN_HOSTS =
%w[github.com gitlab.com codeberg.org].freeze
REASON_NON_RUBYGEMS_SOURCE =

Reasons a resolve might come back without a host coordinate. Surfaced as ‘metadata` on the returned Project so the CLI/TUI can show the user why a gem wasn’t actionable.

:non_rubygems_source
REASON_API_NOT_FOUND =
:api_not_found
REASON_NO_USABLE_URI =
:no_usable_uri
REASON_UNKNOWN_HOST =
:unknown_host

Instance Method Summary collapse

Constructor Details

#initialize(cache: Cache.new, http: Net::HTTP, clock: -> { Time.now.to_i }) ⇒ Resolver

Returns a new instance of Resolver.



29
30
31
32
33
# File 'lib/gem_contribute/resolver.rb', line 29

def initialize(cache: Cache.new, http: Net::HTTP, clock: -> { Time.now.to_i })
  @cache = cache
  @http = http
  @clock = clock
end

Instance Method Details

#resolve(gem) ⇒ Project

Parameters:

Returns:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/gem_contribute/resolver.rb', line 37

def resolve(gem)
  return unresolved(gem, REASON_NON_RUBYGEMS_SOURCE) unless gem.resolvable?

   = (gem)
  return unresolved(gem, REASON_API_NOT_FOUND) if .nil?

  uri = preferred_uri()
  return unresolved(gem, REASON_NO_USABLE_URI) if uri.nil?

  coords = parse_host_coordinates(uri)
  return unresolved(gem, REASON_UNKNOWN_HOST, source_url: uri) if coords.nil?

  Project.new(
    gem_name: gem.name,
    host: coords[:host],
    owner: coords[:owner],
    repo: coords[:repo],
    metadata: { source_url: uri, picked_from: coords[:picked_from] }
  )
end