Class: Rubycc::Doctor::VerifiedGems
- Inherits:
-
Object
- Object
- Rubycc::Doctor::VerifiedGems
- Defined in:
- lib/rubycc/doctor/verified_gems.rb
Overview
The build-verified gem database (data/verified_gems.json), the primary
reference rubycc doctor consults before ever attempting a build. A gem whose
resolved version satisfies one of the recorded versions entries is reported
as verified with no network access and no build.
The schema is documented in data/README.md. One gem is one entry, and an entry holds a list of verifications -- one per environment it was confirmed in, in insertion (oldest-first) order:
{ "json": { "verifications": [ { "versions": ["2.21.1"],
"environment": "glibc x86_64 / ruby 3.4.5",
"verified_at": "2026-07-17",
"evidence": "..." } ],
"notes": "..." } }
versions sits inside each record rather than once at the entry level
because the versions actually exercised may differ per environment; hoisting
them would claim more than was measured. The absence of a record is itself
the statement that the gem is unverified in that environment.
Version entries are matched with Gem::Requirement, so both exact pins ("2.21.1") and ranges (">= 1.8, < 2") work.
Defined Under Namespace
Classes: Record, Verification
Constant Summary collapse
- DEFAULT_PATH =
data/verified_gems.json relative to this file (lib/rubycc/doctor/).
File.("../../../data/verified_gems.json", __dir__)
Instance Attribute Summary collapse
-
#records ⇒ Object
readonly
All records (used by the schema test and for listing).
Class Method Summary collapse
-
.load(path = DEFAULT_PATH) ⇒ Object
Load the database from
path(defaults to the shipped file).
Instance Method Summary collapse
-
#[](name) ⇒ Object
The record for
name, or nil. -
#initialize(raw) ⇒ VerifiedGems
constructor
A new instance of VerifiedGems.
-
#match(name, version) ⇒ Object
The Record that verifies
nameatversion, or nil. -
#matching_verifications(name, version) ⇒ Object
Every Verification of
namewhoseversionscoverversion, in the order they are recorded; empty when nothing matches. -
#verified?(name, version) ⇒ Boolean
Whether
nameatversionis verified.
Constructor Details
#initialize(raw) ⇒ VerifiedGems
Returns a new instance of VerifiedGems.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rubycc/doctor/verified_gems.rb', line 53 def initialize(raw) @records = {} raw.each do |name, attrs| verifications = Array(attrs["verifications"]).map do |v| Verification.new( versions: Array(v["versions"]), environment: v["environment"], verified_at: v["verified_at"], evidence: v["evidence"] ) end @records[name] = Record.new(name: name, verifications: verifications, notes: attrs["notes"]) end end |
Instance Attribute Details
#records ⇒ Object (readonly)
All records (used by the schema test and for listing).
69 70 71 |
# File 'lib/rubycc/doctor/verified_gems.rb', line 69 def records @records end |
Class Method Details
.load(path = DEFAULT_PATH) ⇒ Object
Load the database from path (defaults to the shipped file).
49 50 51 |
# File 'lib/rubycc/doctor/verified_gems.rb', line 49 def self.load(path = DEFAULT_PATH) new(JSON.parse(File.read(path))) end |
Instance Method Details
#[](name) ⇒ Object
The record for name, or nil.
72 73 74 |
# File 'lib/rubycc/doctor/verified_gems.rb', line 72 def [](name) @records[name] end |
#match(name, version) ⇒ Object
The Record that verifies name at version, or nil. A version satisfies
an entry when at least one of its verifications covers it -- being
verified in any one environment is what "verified" has always meant here,
and splitting the schema per environment must not narrow it.
86 87 88 89 90 91 |
# File 'lib/rubycc/doctor/verified_gems.rb', line 86 def match(name, version) record = @records[name] return nil if record.nil? || matching_verifications(name, version).empty? record end |
#matching_verifications(name, version) ⇒ Object
Every Verification of name whose versions cover version, in the
order they are recorded; empty when nothing matches. This is what a caller
asks when it needs to say where the version was verified, not just
whether it was.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/rubycc/doctor/verified_gems.rb', line 97 def matching_verifications(name, version) record = @records[name] return [] unless record && version gem_version = Gem::Version.new(version) record.verifications.select do |verification| verification.versions.any? do |req| # A range entry may be comma-joined (">= 1.8, < 2"); split it into the # individual constraints Gem::Requirement expects as separate arguments. Gem::Requirement.new(*req.split(",").map(&:strip)).satisfied_by?(gem_version) rescue ArgumentError false end end end |
#verified?(name, version) ⇒ Boolean
Whether name at version is verified. A nil version can never match an
exact pin, so an unknown version is treated as not verified.
78 79 80 |
# File 'lib/rubycc/doctor/verified_gems.rb', line 78 def verified?(name, version) !match(name, version).nil? end |