Class: Bibliothecary::Parsers::Rubygems
- Inherits:
-
Object
- Object
- Bibliothecary::Parsers::Rubygems
- Extended by:
- MultiParsers::BundlerLikeManifest
- Includes:
- Analyser
- Defined in:
- lib/bibliothecary/parsers/rubygems.rb
Constant Summary collapse
- NAME_VERSION =
'(?! )(.*?)(?: \(([^-]*)(?:-(.*))?\))?'- NAME_VERSION_4 =
/^ {4}#{NAME_VERSION}$/- BUNDLED_WITH =
/BUNDLED WITH/
Class Method Summary collapse
- .mapping ⇒ Object
- .parse_bundler(file_contents, source = nil) ⇒ Object
- .parse_gemfile(file_contents, options: {}) ⇒ Object
- .parse_gemfile_lock(file_contents, options: {}) ⇒ Object
- .parse_gemspec(file_contents, options: {}) ⇒ Object
Methods included from MultiParsers::BundlerLikeManifest
Methods included from Analyser
create_analysis, create_error_analysis, included
Class Method Details
.mapping ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bibliothecary/parsers/rubygems.rb', line 15 def self.mapping { match_filenames("Gemfile", "gems.rb") => { kind: "manifest", parser: :parse_gemfile, related_to: %w[manifest lockfile], }, match_extension(".gemspec") => { kind: "manifest", parser: :parse_gemspec, related_to: %w[manifest lockfile], }, match_filenames("Gemfile.lock", "gems.locked") => { kind: "lockfile", parser: :parse_gemfile_lock, related_to: %w[manifest lockfile], }, } end |
.parse_bundler(file_contents, source = nil) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/bibliothecary/parsers/rubygems.rb', line 74 def self.parse_bundler(file_contents, source = nil) bundled_with_index = file_contents.lines(chomp: true).find_index { |line| line.match(BUNDLED_WITH) } version = file_contents.lines(chomp: true).fetch(bundled_with_index + 1)&.strip return nil unless version Dependency.new( name: "bundler", requirement: version, type: "runtime", source: source, platform: platform_name ) end |
.parse_gemfile(file_contents, options: {}) ⇒ Object
62 63 64 65 66 |
# File 'lib/bibliothecary/parsers/rubygems.rb', line 62 def self.parse_gemfile(file_contents, options: {}) manifest = Gemnasium::Parser.send(:gemfile, file_contents) dependencies = parse_ruby_manifest(manifest, platform_name, .fetch(:filename, nil)) ParserResult.new(dependencies: dependencies) end |
.parse_gemfile_lock(file_contents, options: {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bibliothecary/parsers/rubygems.rb', line 39 def self.parse_gemfile_lock(file_contents, options: {}) dependencies = file_contents.lines(chomp: true).map do |line| match = line.match(NAME_VERSION_4) bundler_match = line.match(BUNDLED_WITH) next unless match || bundler_match if match name = match[1] version = match[2].gsub(/\(|\)/, "") Dependency.new( name: name, requirement: version, type: "runtime", source: .fetch(:filename, nil), platform: platform_name ) else parse_bundler(file_contents, .fetch(:filename, nil)) end end.compact ParserResult.new(dependencies: dependencies) end |
.parse_gemspec(file_contents, options: {}) ⇒ Object
68 69 70 71 72 |
# File 'lib/bibliothecary/parsers/rubygems.rb', line 68 def self.parse_gemspec(file_contents, options: {}) manifest = Gemnasium::Parser.send(:gemspec, file_contents) dependencies = parse_ruby_manifest(manifest, platform_name, .fetch(:filename, nil)) ParserResult.new(dependencies: dependencies) end |