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



12
13
14
# File 'lib/gem/guardian/lockfile_parser.rb', line 12

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



12
13
14
# File 'lib/gem/guardian/lockfile_parser.rb', line 12

def checksums_section_present
  @checksums_section_present
end

#dependenciesObject (readonly)

Returns the value of attribute dependencies

Returns:

  • (Object)

    the current value of dependencies



12
13
14
# File 'lib/gem/guardian/lockfile_parser.rb', line 12

def dependencies
  @dependencies
end

Instance Method Details

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

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



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

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)


32
33
34
# File 'lib/gem/guardian/lockfile_parser.rb', line 32

def checksums_present?
  checksums_section_present
end

#missing_checksum_dependenciesObject

Returns dependencies that do not have a sha256 checksum.



27
28
29
# File 'lib/gem/guardian/lockfile_parser.rb', line 27

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

#sha256_checksumsObject

Returns a dependency => sha256 checksum map.



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

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