Class: Synvert::Core::Rewriter::GemSpec
- Inherits:
-
Object
- Object
- Synvert::Core::Rewriter::GemSpec
- Defined in:
- lib/synvert/core/rewriter/gem_spec.rb
Overview
GemSpec checks and compares gem version.
Constant Summary collapse
- OPERATORS =
{ eq: '==', lt: '<', gt: '>', lte: '<=', gte: '>=', ne: '!=' }.freeze
Instance Method Summary collapse
-
#initialize(name, comparator) ⇒ GemSpec
constructor
Initialize a gem_spec.
-
#match? ⇒ Boolean
Check if the specified gem version in Gemfile.lock matches gem_spec comparator.
Constructor Details
#initialize(name, comparator) ⇒ GemSpec
Initialize a gem_spec.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/synvert/core/rewriter/gem_spec.rb', line 13 def initialize(name, comparator) @name = name if comparator.is_a?(Hash) @operator = comparator.keys.first @version = Gem::Version.new comparator.values.first else @operator = :eq @version = Gem::Version.new comparator end end |
Instance Method Details
#match? ⇒ Boolean
Check if the specified gem version in Gemfile.lock matches gem_spec comparator.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/synvert/core/rewriter/gem_spec.rb', line 28 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)) if spec = parser.specs.find { |spec| spec.name == @name } Gem::Version.new(spec.version).send(OPERATORS[@operator], @version) else false end end |