Module: Rails::Hyperdrive::DriftVerdict
- Defined in:
- lib/rails/hyperdrive/drift_verdict.rb
Overview
The lock's source_sha is computed over the install-ready body before any header injection, so hashing an installed file's comparable bytes (disk_sha) reproduces it exactly for an unedited file.
Constant Summary collapse
- STATES =
%i[current outdated edited missing orphaned].freeze
Class Method Summary collapse
-
.body_sha(content) ⇒ Object
The install-ready body's hash — what the lock records as source_sha.
-
.disk_sha(file, kind:) ⇒ Object
AuditHeader.strip's line matching can raise on binary content, so skill_support files compare as raw bytes.
-
.unedited?(file, lock_entry:) ⇒ Boolean
A file counts as unedited when its comparable bytes still hash to what the lock recorded at install time, not to what the gem ships now.
-
.verdict(file:, kind:, lock_entry:, gem_sha:) ⇒ Object
gem_sha nil means the bundle no longer offers this destination.
Class Method Details
.body_sha(content) ⇒ Object
The install-ready body's hash — what the lock records as source_sha.
15 16 17 |
# File 'lib/rails/hyperdrive/drift_verdict.rb', line 15 def body_sha(content) Digest::SHA256.hexdigest(content.to_s) end |
.disk_sha(file, kind:) ⇒ Object
AuditHeader.strip's line matching can raise on binary content, so skill_support files compare as raw bytes.
21 22 23 24 |
# File 'lib/rails/hyperdrive/drift_verdict.rb', line 21 def disk_sha(file, kind:) return body_sha(File.binread(file)) if kind.to_s == "skill_support" body_sha(AuditHeader.strip(File.read(file))) end |
.unedited?(file, lock_entry:) ⇒ Boolean
A file counts as unedited when its comparable bytes still hash to what the lock recorded at install time, not to what the gem ships now.
28 29 30 |
# File 'lib/rails/hyperdrive/drift_verdict.rb', line 28 def unedited?(file, lock_entry:) disk_sha(file, kind: lock_entry.kind) == lock_entry.source_sha end |
.verdict(file:, kind:, lock_entry:, gem_sha:) ⇒ Object
gem_sha nil means the bundle no longer offers this destination.
33 34 35 36 37 38 39 |
# File 'lib/rails/hyperdrive/drift_verdict.rb', line 33 def verdict(file:, kind:, lock_entry:, gem_sha:) return File.exist?(file) ? :orphaned : :missing if gem_sha.nil? return :missing unless File.exist?(file) return :edited if lock_entry.nil? return :edited if disk_sha(file, kind: kind) != lock_entry.source_sha lock_entry.source_sha == gem_sha ? :current : :outdated end |