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: '!='}
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 Hash === comparator @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 |
# File 'lib/synvert/core/rewriter/gem_spec.rb', line 28 def match? gemfile_lock_path = File.join(Configuration.instance.get(:path), 'Gemfile.lock') if File.exists? gemfile_lock_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 else raise GemfileLockNotFound.new 'Gemfile.lock does not exist' end end |