Class: Rails::Hyperdrive::ArtifactStatus
- Inherits:
-
Object
- Object
- Rails::Hyperdrive::ArtifactStatus
- Defined in:
- lib/rails/hyperdrive/artifact_status.rb
Overview
The comparison is against the lock manifest alone — installed files are never read, so an edited or deleted file does not change a verdict.
Defined Under Namespace
Classes: Entry
Constant Summary collapse
- STATES =
%i[installed missing outdated orphaned].freeze
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Class Method Summary collapse
Instance Method Summary collapse
- #compare ⇒ Object
-
#initialize(root:, artifacts:) ⇒ ArtifactStatus
constructor
A new instance of ArtifactStatus.
- #stale? ⇒ Boolean
Constructor Details
#initialize(root:, artifacts:) ⇒ ArtifactStatus
Returns a new instance of ArtifactStatus.
30 31 32 33 34 |
# File 'lib/rails/hyperdrive/artifact_status.rb', line 30 def initialize(root:, artifacts:) @root = File.(root.to_s) @artifacts = artifacts @entries = [] end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
28 29 30 |
# File 'lib/rails/hyperdrive/artifact_status.rb', line 28 def entries @entries end |
Class Method Details
.compare(root:, artifacts:) ⇒ Object
24 25 26 |
# File 'lib/rails/hyperdrive/artifact_status.rb', line 24 def self.compare(root:, artifacts:) new(root: root, artifacts: artifacts).tap(&:compare) end |
Instance Method Details
#compare ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rails/hyperdrive/artifact_status.rb', line 36 def compare lock = LockFile.load(File.join(@root, InstallLayout::LOCK_PATH)) offered = {} InstallPlan.build(@artifacts, lock: lock).entries.each do |plan_entry| offered[plan_entry.dest] = [DriftVerdict.body_sha(plan_entry.install_ready_body), plan_entry.source_label, plan_entry.type] plan_entry.support_files.each do |file| offered[file[:dest]] = [DriftVerdict.body_sha(file[:body]), plan_entry.source_label, :skill_support] end end offered.each do |path, (gem_sha, source_label, type)| locked = lock.entry(path) state = if locked.nil? then :missing elsif locked.source_sha == gem_sha then :installed else :outdated end @entries << Entry.new( path: path, state: state, artifact: type, locked_source: locked&.source_label, bundle_source: source_label ) end lock.each_entry do |locked| next if offered.key?(locked.path) # A disabled artifact left on disk was reported at install time; the # bundle still ships it, so it is not an orphan. type = InstallLayout::ARTIFACT_TYPES[locked.kind] next if type && InstallPlan.disabled_dest?(lock, type, locked.path) @entries << Entry.new( path: locked.path, state: :orphaned, artifact: locked.kind&.to_sym, locked_source: locked.source_label, bundle_source: nil ) end self end |
#stale? ⇒ Boolean
81 82 83 |
# File 'lib/rails/hyperdrive/artifact_status.rb', line 81 def stale? !missing.empty? || !outdated.empty? || !orphaned.empty? end |