Class: Gem::Guardian::LockfileParser::LockfileData

Inherits:
Data
  • Object
show all
Defined in:
lib/gem/guardian/lockfile_parser.rb

Overview

Parsed lockfile data for the verify command.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#checksumsObject (readonly)

Returns the value of attribute checksums

Returns:

  • (Object)

    the current value of checksums



14
15
16
# File 'lib/gem/guardian/lockfile_parser.rb', line 14

def checksums
  @checksums
end

#checksums_section_presentObject (readonly)

Returns the value of attribute checksums_section_present

Returns:

  • (Object)

    the current value of checksums_section_present



14
15
16
# File 'lib/gem/guardian/lockfile_parser.rb', line 14

def checksums_section_present
  @checksums_section_present
end

#dependenciesObject (readonly)

Returns the value of attribute dependencies

Returns:

  • (Object)

    the current value of dependencies



14
15
16
# File 'lib/gem/guardian/lockfile_parser.rb', line 14

def dependencies
  @dependencies
end

Instance Method Details

#checksum_for(dependency, algorithm = "sha256") ⇒ Object

Returns the checksum for +dependency+ and +algorithm+, if present.



16
17
18
# File 'lib/gem/guardian/lockfile_parser.rb', line 16

def checksum_for(dependency, algorithm = "sha256")
  checksums.fetch(dependency, {}).fetch(algorithm, nil)
end

#checksums_present?Boolean

Returns true if the lockfile contained a CHECKSUMS section.

Returns:

  • (Boolean)


34
35
36
# File 'lib/gem/guardian/lockfile_parser.rb', line 34

def checksums_present?
  checksums_section_present
end

#missing_checksum_dependenciesObject

Returns dependencies that do not have a sha256 checksum.



29
30
31
# File 'lib/gem/guardian/lockfile_parser.rb', line 29

def missing_checksum_dependencies
  dependencies.reject { |dependency| sha256_checksums.key?(dependency) }
end

#sha256_checksumsObject

Returns a dependency => sha256 checksum map.



21
22
23
24
25
26
# File 'lib/gem/guardian/lockfile_parser.rb', line 21

def sha256_checksums
  checksums.each_with_object({}) do |(dependency, algorithms), memo|
    digest = algorithms["sha256"]
    memo[dependency] = digest if digest
  end
end