Sha256: 4c65b18ba0ddff1dae4dda0e32cf41f6c171065c704eea5de97f00bba85a838a

Contents?: true

Size: 1.08 KB

Versions: 64

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Synvert::Core
  # GemSpec checks and compares gem version.
  class Rewriter::GemSpec
    attr_reader :name, :version

    # Initialize a gem_spec.
    #
    # @param name [String] gem name
    # @param version [String] gem version, e.g. '~> 2.0.0',
    def initialize(name, version)
      @name = name
      @version = version
    end

    # 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.
    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
  end
end

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
synvert-core-0.63.0 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-0.62.1 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-0.62.0 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-0.61.2 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-0.61.1 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-0.61.0 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-0.60.0 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-0.59.0 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-0.58.3 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-0.58.2 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-0.58.0 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-0.57.1 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-0.57.0 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-0.56.1 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-0.56.0 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-0.55.0 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-0.54.3 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-0.54.2 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-0.54.1 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-0.54.0 lib/synvert/core/rewriter/gem_spec.rb