class Bibliothecary::Parsers::Rubygems
Constants
- BUNDLED_WITH
- NAME_VERSION
- NAME_VERSION_4
Public Class Methods
mapping()
click to toggle source
# 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)
click to toggle source
# 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 Dependency.new( name: "bundler", requirement: version, type: "runtime", ) end
parse_gemfile(file_contents, options: {})
click to toggle source
# 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: {})
click to toggle source
# 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(/\(|\)/,"") Dependency.new( name: name, requirement: version, type: "runtime", ) else parse_bundler(file_contents) end end.compact end
parse_gemspec(file_contents, options: {})
click to toggle source
# 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