Class: Rails::Hyperdrive::CompanionDiscovery
- Inherits:
-
Object
- Object
- Rails::Hyperdrive::CompanionDiscovery
- Defined in:
- lib/rails/hyperdrive/companion_discovery.rb
Defined Under Namespace
Classes: NetHttpFetcher, Response, Result, Suggestion, Unavailable
Constant Summary collapse
- TARGETS_KEY =
"rails_hyperdrive_targets".freeze
- ARTIFACTS_KEY =
"rails_hyperdrive_artifacts".freeze
- SEARCH_QUERY =
Field-scoped metadata search is an undocumented passthrough to the rubygems search backend, so it fails open: if it ever stops matching, the query returns an empty 200 page and discovery reports no suggestions.
"metadata.#{TARGETS_KEY}:*".freeze
- SEARCH_ENDPOINT =
"https://rubygems.org/api/v1/search.json".freeze
- CACHE_RELATIVE_PATH =
".hyperdrive/discover_cache.json".freeze
- PER_PAGE =
30- MAX_PAGES =
~1000 companions; a runaway-pagination backstop
34- CACHE_TTL =
24 * 60 * 60
- OPEN_TIMEOUT =
5- READ_TIMEOUT =
5
Instance Method Summary collapse
-
#initialize(lockfile_path:, cache_path:, refresh: false, fetcher: NetHttpFetcher.new, clock: -> { Time.now.utc }) ⇒ CompanionDiscovery
constructor
A new instance of CompanionDiscovery.
- #run ⇒ Object
Constructor Details
#initialize(lockfile_path:, cache_path:, refresh: false, fetcher: NetHttpFetcher.new, clock: -> { Time.now.utc }) ⇒ CompanionDiscovery
Returns a new instance of CompanionDiscovery.
63 64 65 66 67 68 69 |
# File 'lib/rails/hyperdrive/companion_discovery.rb', line 63 def initialize(lockfile_path:, cache_path:, refresh: false, fetcher: NetHttpFetcher.new, clock: -> { Time.now.utc }) @lockfile_path = lockfile_path.to_s @cache_path = cache_path.to_s @refresh = refresh @fetcher = fetcher @clock = clock end |
Instance Method Details
#run ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rails/hyperdrive/companion_discovery.rb', line 71 def run warnings = [] now = @clock.call candidates, status, age, detail = resolve_candidates(now) return Result.new(suggestions: [], warnings: warnings, status: :unavailable, detail: detail) if status == :unavailable suggestions = match(candidates, warnings) Result.new(suggestions: suggestions, warnings: warnings, status: status, age_seconds: age, detail: detail) end |