Module: Rails::Hyperdrive::DriftVerdict
- Defined in:
- lib/rails/hyperdrive/drift_verdict.rb
Overview
Installed files are byte-identical to their install-ready body, so an unedited file's disk hash reproduces the lock's source_sha exactly.
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) ⇒ Object
-
.unedited?(file, lock_entry:) ⇒ Boolean
A file counts as unedited when its bytes still hash to what the lock recorded at install time, not to what the gem ships now.
-
.verdict(file:, 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.
13 14 15 |
# File 'lib/rails/hyperdrive/drift_verdict.rb', line 13 def body_sha(content) Digest::SHA256.hexdigest(content.to_s) end |
.disk_sha(file) ⇒ Object
17 18 19 |
# File 'lib/rails/hyperdrive/drift_verdict.rb', line 17 def disk_sha(file) body_sha(File.binread(file)) end |
.unedited?(file, lock_entry:) ⇒ Boolean
A file counts as unedited when its bytes still hash to what the lock recorded at install time, not to what the gem ships now.
23 24 25 |
# File 'lib/rails/hyperdrive/drift_verdict.rb', line 23 def unedited?(file, lock_entry:) disk_sha(file) == lock_entry.source_sha end |
.verdict(file:, lock_entry:, gem_sha:) ⇒ Object
gem_sha nil means the bundle no longer offers this destination.
28 29 30 31 32 33 34 |
# File 'lib/rails/hyperdrive/drift_verdict.rb', line 28 def verdict(file:, 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) != lock_entry.source_sha lock_entry.source_sha == gem_sha ? :current : :outdated end |