class Synvert::Core::Rewriter::GemSpec
GemSpec
checks and compares gem version.
Attributes
name[R]
version[R]
Public Class Methods
new(name, version)
click to toggle source
Initialize a gem_spec.
@param name [String] gem name @param version [String] gem version, e.g. '~> 2.0.0',
# File lib/synvert/core/rewriter/gem_spec.rb, line 12 def initialize(name, version) @name = name @version = version end
Public Instance Methods
match?()
click to toggle source
Check if the specified gem version in Gemfile.lock matches gem_spec comparator.
@return [Boolean] true if matches, otherwise false. @raise [Synvert::Core::GemfileLockNotFound] raise if Gemfile.lock does not exist.
# File lib/synvert/core/rewriter/gem_spec.rb, line 21 def match? gemfile_lock_path = File.join(Configuration.path, 'Gemfile.lock') # if Gemfile.lock does not exist, just ignore this check return true unless File.exist?(gemfile_lock_path) ENV['BUNDLE_GEMFILE'] = Configuration.path # make sure bundler reads Gemfile.lock in the correct path parser = Bundler::LockfileParser.new(File.read(gemfile_lock_path)) parser.specs.any? { |spec| Gem::Dependency.new(@name, @version).match?(spec) } end