Class: LicenseAuto::Bundler
Constant Summary
collapse
- LANGUAGE =
'Ruby'
Instance Method Summary
collapse
#dependency_file_path_names
Constructor Details
#initialize(path) ⇒ Bundler
Returns a new instance of Bundler.
11
12
13
|
# File 'lib/license_auto/package_manager/bundler.rb', line 11
def initialize(path)
super(path)
end
|
Instance Method Details
#dependency_file_pattern ⇒ Object
15
16
17
|
# File 'lib/license_auto/package_manager/bundler.rb', line 15
def dependency_file_pattern
/#{@path}\/gem.*\.lock$/i
end
|
#gemfile_pattern ⇒ Object
19
20
21
|
# File 'lib/license_auto/package_manager/bundler.rb', line 19
def gemfile_pattern
/gemfile$/i
end
|
#parse_dependencies ⇒ Object
23
24
25
26
27
28
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/license_auto/package_manager/bundler.rb', line 23
def parse_dependencies
lock_files = dependency_file_path_names
if lock_files.empty?
LicenseAuto.logger.info("Gemfile.lock file not exisit")
gem_files = dependency_file_path_names(pattern=gemfile_pattern)
unless gem_files.empty?
LicenseAuto.logger.info("Gemfile exisit: #{gem_files}")
end
return []
else
lock_files.map {|dep_file|
LicenseAuto.logger.debug(dep_file)
lockfile_parser = ::Bundler::LockfileParser.new(::Bundler.read_file(dep_file))
{
dep_file: dep_file,
deps: lockfile_parser.specs.map {|spec|
remote =
case
when spec.source.class == ::Bundler::Source::Git
spec.source.uri
when spec.source.class == ::Bundler::Source::Rubygems
if spec.source.remotes.size == 1
spec.source.remotes.first.to_s
elsif spec.source.remotes.size >= 1
spec.source.remotes.map {|r|
r.to_s
}.join(',')
end
when spec.source.class == ::Bundler::Source::Path::Installer
spec.full_gem_path
else
raise('Yo, this error should ever not occur!')
end
{
name: spec.name,
version: spec.version.to_s,
remote: remote
}
}
}
}
end
end
|