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
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/bibliothecary/parsers/rubygems.rb', line 70 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 ) end |
.parse_gemfile(file_contents, options: {}) ⇒ Object
60 61 62 63 |
# File 'lib/bibliothecary/parsers/rubygems.rb', line 60 def self.parse_gemfile(file_contents, options: {}) manifest = Gemnasium::Parser.send(:gemfile, file_contents) parse_ruby_manifest(manifest, .fetch(:filename, nil)) 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 |
# File 'lib/bibliothecary/parsers/rubygems.rb', line 39 def self.parse_gemfile_lock(file_contents, options: {}) 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) ) else parse_bundler(file_contents, .fetch(:filename, nil)) end end.compact end |
.parse_gemspec(file_contents, options: {}) ⇒ Object
65 66 67 68 |
# File 'lib/bibliothecary/parsers/rubygems.rb', line 65 def self.parse_gemspec(file_contents, options: {}) manifest = Gemnasium::Parser.send(:gemspec, file_contents) parse_ruby_manifest(manifest, .fetch(:filename, nil)) end |