Module: StillActive::AlternativesHelper
- Extended by:
- AlternativesHelper
- Included in:
- AlternativesHelper
- Defined in:
- lib/helpers/alternatives_helper.rb
Overview
Turns a gem’s catalog siblings into ranked “leads” – the most-downloaded still-published alternatives. Best-effort: a failed lookup drops that candidate, never the feature.
Constant Summary collapse
- MAX_SIBLINGS_CONSIDERED =
bound the download lookups for huge categories
40- DEFAULT_LIMIT =
3
Instance Method Summary collapse
Instance Method Details
#leads_for(gem_name:, index:, limit: DEFAULT_LIMIT) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/helpers/alternatives_helper.rb', line 15 def leads_for(gem_name:, index:, limit: DEFAULT_LIMIT) return [] if index.nil? # Bound the per-gem download lookups so a huge category can't trigger # dozens of HTTP calls. This is a catalog-order prefix, so a very large # category could leave a popular sibling past the cap out of the ranking; # acceptable for best-effort leads where we only ever surface a few. # (CatalogIndex already reduces owner/repo slugs to their gem-name tail, # so every entry here is a plain name rankable by downloads.) siblings = (index[gem_name] || []).first(MAX_SIBLINGS_CONSIDERED) return [] if siblings.empty? siblings .filter_map { |name| (count = downloads(name)) && [name, count] } .max_by(limit) { |_name, count| count } .map(&:first) end |