Class: Gem::Guardian::CLI::LockfileDataView
- Inherits:
-
Data
- Object
- Data
- Gem::Guardian::CLI::LockfileDataView
- Defined in:
- lib/gem/guardian/cli.rb
Overview
Lightweight lockfile data adapter used when a user verifies only a subset of gems from a Bundler lockfile.
LockfileParser returns the full dependency graph and all parsed checksum
entries. When the CLI receives both --lockfile and explicit
GEM:VERSION[:PLATFORM] arguments, this view narrows that data to the
requested dependencies while preserving the same reader methods consumed by
Verifier, ReportBuilder, and ResultPrinter.
Instance Attribute Summary collapse
-
#checksums ⇒ Hash{Dependency => Hash{String => String}}
readonly
Checksum algorithms keyed by dependency.
-
#checksums_section_present ⇒ Boolean
readonly
Whether the source lockfile contained a
CHECKSUMSsection. -
#dependencies ⇒ Array<Dependency>
readonly
Dependencies selected for verification.
Instance Method Summary collapse
-
#checksum_for(dependency, algorithm = "sha256") ⇒ String?
Looks up a checksum for a dependency and algorithm.
-
#checksums_present? ⇒ Boolean
Indicates whether the original lockfile contained a
CHECKSUMSsection. -
#missing_checksum_dependencies ⇒ Array<Dependency>
Lists selected dependencies that do not have SHA256 lockfile coverage.
-
#sha256_checksums ⇒ Hash{Dependency => String}
Returns only SHA256 checksums from the filtered lockfile data.
Instance Attribute Details
#checksums ⇒ Hash{Dependency => Hash{String => String}} (readonly)
Returns checksum algorithms keyed by dependency.
29 30 31 32 33 34 35 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 |
# File 'lib/gem/guardian/cli.rb', line 29 LockfileDataView = Data.define(:dependencies, :checksums, :checksums_section_present) do # Looks up a checksum for a dependency and algorithm. # # @param dependency [Dependency] dependency to look up # @param algorithm [String] checksum algorithm name, currently usually # +"sha256"+ # @return [String, nil] checksum digest when present, otherwise +nil+ def checksum_for(dependency, algorithm = "sha256") checksums.fetch(dependency, {}).fetch(algorithm, nil) end # Returns only SHA256 checksums from the filtered lockfile data. # # @return [Hash{Dependency => String}] selected dependencies mapped to # their SHA256 digest def sha256_checksums checksums.each_with_object({}) do |(dependency, algorithms), memo| digest = algorithms["sha256"] memo[dependency] = digest if digest end end # Lists selected dependencies that do not have SHA256 lockfile coverage. # # @return [Array<Dependency>] dependencies missing a SHA256 checksum in # the lockfile view def missing_checksum_dependencies dependencies.reject { |dependency| sha256_checksums.key?(dependency) } end # Indicates whether the original lockfile contained a +CHECKSUMS+ # section. # # @return [Boolean] +true+ when the source lockfile had checksum metadata def checksums_present? checksums_section_present end end |
#checksums_section_present ⇒ Boolean (readonly)
Returns whether the source lockfile contained a CHECKSUMS
section.
29 30 31 32 33 34 35 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 |
# File 'lib/gem/guardian/cli.rb', line 29 LockfileDataView = Data.define(:dependencies, :checksums, :checksums_section_present) do # Looks up a checksum for a dependency and algorithm. # # @param dependency [Dependency] dependency to look up # @param algorithm [String] checksum algorithm name, currently usually # +"sha256"+ # @return [String, nil] checksum digest when present, otherwise +nil+ def checksum_for(dependency, algorithm = "sha256") checksums.fetch(dependency, {}).fetch(algorithm, nil) end # Returns only SHA256 checksums from the filtered lockfile data. # # @return [Hash{Dependency => String}] selected dependencies mapped to # their SHA256 digest def sha256_checksums checksums.each_with_object({}) do |(dependency, algorithms), memo| digest = algorithms["sha256"] memo[dependency] = digest if digest end end # Lists selected dependencies that do not have SHA256 lockfile coverage. # # @return [Array<Dependency>] dependencies missing a SHA256 checksum in # the lockfile view def missing_checksum_dependencies dependencies.reject { |dependency| sha256_checksums.key?(dependency) } end # Indicates whether the original lockfile contained a +CHECKSUMS+ # section. # # @return [Boolean] +true+ when the source lockfile had checksum metadata def checksums_present? checksums_section_present end end |
#dependencies ⇒ Array<Dependency> (readonly)
Returns dependencies selected for verification.
29 30 31 32 33 34 35 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 |
# File 'lib/gem/guardian/cli.rb', line 29 LockfileDataView = Data.define(:dependencies, :checksums, :checksums_section_present) do # Looks up a checksum for a dependency and algorithm. # # @param dependency [Dependency] dependency to look up # @param algorithm [String] checksum algorithm name, currently usually # +"sha256"+ # @return [String, nil] checksum digest when present, otherwise +nil+ def checksum_for(dependency, algorithm = "sha256") checksums.fetch(dependency, {}).fetch(algorithm, nil) end # Returns only SHA256 checksums from the filtered lockfile data. # # @return [Hash{Dependency => String}] selected dependencies mapped to # their SHA256 digest def sha256_checksums checksums.each_with_object({}) do |(dependency, algorithms), memo| digest = algorithms["sha256"] memo[dependency] = digest if digest end end # Lists selected dependencies that do not have SHA256 lockfile coverage. # # @return [Array<Dependency>] dependencies missing a SHA256 checksum in # the lockfile view def missing_checksum_dependencies dependencies.reject { |dependency| sha256_checksums.key?(dependency) } end # Indicates whether the original lockfile contained a +CHECKSUMS+ # section. # # @return [Boolean] +true+ when the source lockfile had checksum metadata def checksums_present? checksums_section_present end end |
Instance Method Details
#checksum_for(dependency, algorithm = "sha256") ⇒ String?
Looks up a checksum for a dependency and algorithm.
36 37 38 |
# File 'lib/gem/guardian/cli.rb', line 36 def checksum_for(dependency, algorithm = "sha256") checksums.fetch(dependency, {}).fetch(algorithm, nil) end |
#checksums_present? ⇒ Boolean
Indicates whether the original lockfile contained a CHECKSUMS
section.
63 64 65 |
# File 'lib/gem/guardian/cli.rb', line 63 def checksums_present? checksums_section_present end |
#missing_checksum_dependencies ⇒ Array<Dependency>
Lists selected dependencies that do not have SHA256 lockfile coverage.
55 56 57 |
# File 'lib/gem/guardian/cli.rb', line 55 def missing_checksum_dependencies dependencies.reject { |dependency| sha256_checksums.key?(dependency) } end |
#sha256_checksums ⇒ Hash{Dependency => String}
Returns only SHA256 checksums from the filtered lockfile data.
44 45 46 47 48 49 |
# File 'lib/gem/guardian/cli.rb', line 44 def sha256_checksums checksums.each_with_object({}) do |(dependency, algorithms), memo| digest = algorithms["sha256"] memo[dependency] = digest if digest end end |