Class: Gistory::LockfileParser
- Inherits:
-
Object
- Object
- Gistory::LockfileParser
- Defined in:
- lib/gistory/lockfile_parser.rb
Instance Method Summary collapse
- #gem_version(gem_name) ⇒ Object
-
#initialize(lockfile_content:) ⇒ LockfileParser
constructor
A new instance of LockfileParser.
Constructor Details
#initialize(lockfile_content:) ⇒ LockfileParser
Returns a new instance of LockfileParser.
7 8 9 |
# File 'lib/gistory/lockfile_parser.rb', line 7 def initialize(lockfile_content:) @lockfile_content = lockfile_content end |
Instance Method Details
#gem_version(gem_name) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/gistory/lockfile_parser.rb', line 11 def gem_version(gem_name) lockfile = Bundler::LockfileParser.new(@lockfile_content) gem_spec = lockfile.specs.find { |spec| spec.name == gem_name } gem_spec ? gem_spec.version.to_s : nil rescue Bundler::LockfileError => _e # bundler could not parse the lockfile # f.i. it could have been committed with merge conflicts # try to parse it with a regex # gem version looks like " byebug (9.0.6)" # TODO: what if the gem was in the merge conflict? regexp = /\n\s{4}#{gem_name} \((?<version>.+)\)\n/ matches = @lockfile_content.match(regexp) matches ? matches[:version] : nil end |