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 =
'(?! )(.*?)(?: \(([^-]*)(?:-(.*))?\))?'.freeze
- NAME_VERSION_4 =
/^ {4}#{NAME_VERSION}$/
- BUNDLED_WITH =
/BUNDLED WITH/
Class Method Summary collapse
- .mapping ⇒ Object
- .parse_bundler(file_contents) ⇒ Object
-
.parse_gemfile(file_contents, options: {}) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
.parse_gemfile_lock(file_contents, options: {}) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
.parse_gemspec(file_contents, options: {}) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
Methods included from MultiParsers::BundlerLikeManifest
Methods included from Analyser
create_analysis, create_error_analysis, included
Class Method Details
.mapping ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bibliothecary/parsers/rubygems.rb', line 13 def self.mapping { match_filenames("Gemfile", "gems.rb") => { kind: "manifest", parser: :parse_gemfile, related_to: [ "manifest", "lockfile" ], }, match_extension(".gemspec") => { kind: "manifest", parser: :parse_gemspec, related_to: [ "manifest", "lockfile" ], }, match_filenames("Gemfile.lock", "gems.locked") => { kind: "lockfile", parser: :parse_gemfile_lock, related_to: [ "manifest", "lockfile" ], }, } end |
.parse_bundler(file_contents) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/bibliothecary/parsers/rubygems.rb', line 67 def self.parse_bundler(file_contents) 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 { name: "bundler", requirement: version, type: "runtime", } end |
.parse_gemfile(file_contents, options: {}) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
57 58 59 60 |
# File 'lib/bibliothecary/parsers/rubygems.rb', line 57 def self.parse_gemfile(file_contents, options: {}) # rubocop:disable Lint/UnusedMethodArgument manifest = Gemnasium::Parser.send(:gemfile, file_contents) parse_ruby_manifest(manifest) end |
.parse_gemfile_lock(file_contents, options: {}) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/bibliothecary/parsers/rubygems.rb', line 37 def self.parse_gemfile_lock(file_contents, options: {}) # rubocop:disable Lint/UnusedMethodArgument 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(/\(|\)/,"") { name: name, requirement: version, type: "runtime", } else parse_bundler(file_contents) end end.compact end |
.parse_gemspec(file_contents, options: {}) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
62 63 64 65 |
# File 'lib/bibliothecary/parsers/rubygems.rb', line 62 def self.parse_gemspec(file_contents, options: {}) # rubocop:disable Lint/UnusedMethodArgument manifest = Gemnasium::Parser.send(:gemspec, file_contents) parse_ruby_manifest(manifest) end |