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.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(name, version) ⇒ 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, version) ⇒ GemSpec
Initialize a gem_spec.
12 13 14 15 |
# File 'lib/synvert/core/rewriter/gem_spec.rb', line 12 def initialize(name, version) @name = name @version = version end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/synvert/core/rewriter/gem_spec.rb', line 6 def name @name end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
6 7 8 |
# File 'lib/synvert/core/rewriter/gem_spec.rb', line 6 def version @version end |
Instance Method Details
#match? ⇒ Boolean
Check if the specified gem version in Gemfile.lock matches gem_spec comparator.
21 22 23 24 25 26 27 28 29 30 |
# 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 |