Class: Gem::Guardian::LockfileParser
- Inherits:
-
Object
- Object
- Gem::Guardian::LockfileParser
- Defined in:
- lib/gem/guardian/lockfile_parser.rb
Overview
Parses Gemfile.lock and exposes dependencies and checksum data.
Defined Under Namespace
Classes: LockfileData
Constant Summary collapse
- GEM_LINE =
Matches dependency lines in the specs section.
/^ {4}([A-Za-z0-9_.-]+) \(([^)]+)\)/- CHECKSUM_LINE =
Matches checksum lines in the CHECKSUMS section.
/^ {2}([A-Za-z0-9_.-]+) \(([^)]+)\) (.+)$/
Instance Method Summary collapse
-
#checksums ⇒ Object
Returns the raw checksum map extracted from the lockfile.
-
#dependencies ⇒ Object
Returns the dependencies listed in the lockfile.
-
#initialize(path = "Gemfile.lock") ⇒ LockfileParser
constructor
A new instance of LockfileParser.
-
#parse ⇒ Object
Parses the lockfile into dependencies and checksum metadata.
Constructor Details
#initialize(path = "Gemfile.lock") ⇒ LockfileParser
Returns a new instance of LockfileParser.
37 38 39 |
# File 'lib/gem/guardian/lockfile_parser.rb', line 37 def initialize(path = "Gemfile.lock") @path = path end |
Instance Method Details
#checksums ⇒ Object
Returns the raw checksum map extracted from the lockfile.
64 65 66 |
# File 'lib/gem/guardian/lockfile_parser.rb', line 64 def checksums parse.checksums end |
#dependencies ⇒ Object
Returns the dependencies listed in the lockfile.
59 60 61 |
# File 'lib/gem/guardian/lockfile_parser.rb', line 59 def dependencies parse.dependencies end |
#parse ⇒ Object
Parses the lockfile into dependencies and checksum metadata.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/gem/guardian/lockfile_parser.rb', line 42 def parse raise LockfileError, "Lockfile not found: #{@path}" unless File.file?(@path) dependencies = [] checksums = {} section = nil File.readlines(@path, chomp: true).each do |line| section = section_for(line, section) parse_specs_line(line, dependencies) if section == :specs parse_checksums_line(line, checksums) if section == :checksums end LockfileData.new(dependencies, checksums, checksums.any?) end |