Sha256: 80d5d336edcc69e5bd4ecd957c164f590eec7e89d1355aa96e625bcc9940b6a6

Contents?: true

Size: 1.18 KB

Versions: 15

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

require 'bundler'

module Synvert::Core
  # GemSpec checks and compares gem version.
  class Rewriter::GemSpec
    # @!attribute [r] name
    #   @return [String] the name of gem_spec
    # @!attribute [r] version
    #   @return [String] the version of gem_spec
    attr_reader :name, :version

    # Initialize a GemSpec.
    #
    # @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.
    def match?
      gemfile_lock_path = File.expand_path(File.join(Configuration.root_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.root_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

15 entries across 15 versions & 1 rubygems

Version Path
synvert-core-1.30.1 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-1.30.0 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-1.29.4 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-1.29.3 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-1.29.2 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-1.29.1 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-1.29.0 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-1.28.5 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-1.28.4 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-1.28.3 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-1.28.2 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-1.28.1 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-1.28.0 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-1.27.1 lib/synvert/core/rewriter/gem_spec.rb
synvert-core-1.27.0 lib/synvert/core/rewriter/gem_spec.rb