5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/gem_guard/parser.rb', line 5
def parse(lockfile_path)
content = File.read(lockfile_path)
begin
lockfile = Bundler::LockfileParser.new(content)
rescue => e
raise GemGuard::InvalidLockfileError, "Invalid Gemfile.lock at #{lockfile_path}: #{e.message}"
end
unless content.include?("\nBUNDLED WITH") || content.end_with?("BUNDLED WITH\n")
raise GemGuard::InvalidLockfileError, "Invalid Gemfile.lock at #{lockfile_path}: missing 'BUNDLED WITH' section"
end
dependencies = []
lockfile.specs.each do |spec|
dependencies << Dependency.new(
name: spec.name,
version: spec.version.to_s,
source: (spec),
dependencies: spec.dependencies.map(&:name)
)
end
validate_dependencies_section!(content, dependencies.map(&:name), lockfile_path)
dependencies.uniq { |dep| dep.name }
end
|