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:, bundled_gems: []) ⇒ ArtifactStatus
constructor
A new instance of ArtifactStatus.
- #stale? ⇒ Boolean
Constructor Details
#initialize(root:, artifacts:, bundled_gems: []) ⇒ ArtifactStatus
Returns a new instance of ArtifactStatus.
37 38 39 40 41 42 |
# File 'lib/rails/hyperdrive/artifact_status.rb', line 37 def initialize(root:, artifacts:, bundled_gems: []) @root = File.(root.to_s) @artifacts = artifacts @bundled_gems = Array(bundled_gems).map(&:to_s) @entries = [] end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
35 36 37 |
# File 'lib/rails/hyperdrive/artifact_status.rb', line 35 def entries @entries end |
Class Method Details
.compare(root:, artifacts:, bundled_gems: []) ⇒ Object
31 32 33 |
# File 'lib/rails/hyperdrive/artifact_status.rb', line 31 def self.compare(root:, artifacts:, bundled_gems: []) new(root: root, artifacts: artifacts, bundled_gems: bundled_gems).tap(&:compare) end |
Instance Method Details
#compare ⇒ Object
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 76 77 78 79 80 81 82 83 84 |
# File 'lib/rails/hyperdrive/artifact_status.rb', line 44 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, source_gem: locked.source_gem) @entries << Entry.new( path: locked.path, state: :orphaned, artifact: locked.kind&.to_sym, locked_source: locked.source_label, bundle_source: nil, source_gem: locked.source_gem, source_bundled: @bundled_gems.include?(locked.source_gem.to_s) ) end self end |
#stale? ⇒ Boolean
90 91 92 |
# File 'lib/rails/hyperdrive/artifact_status.rb', line 90 def stale? !missing.empty? || !outdated.empty? || !orphaned.empty? end |