Sha256: 3679e4e63fdb7aec2f88cfeb5999a156525e2b529048e3e1d01883dd05a2a057

Contents?: true

Size: 1.43 KB

Versions: 3

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

module NeetoCompliance
  class BundlerVersionVerifier < Base
    def latest_bundler_version
      @_latest_bundler_version ||= _latest_bundler_version
    end

    def _latest_bundler_version
      response = Net::HTTP.get(URI("https://rubygems.org/api/v1/versions/bundler.json"))
      JSON.parse(response)[0]["number"]
    end

    def current_bundler_version
      `tail -n 1 ./Gemfile.lock`.strip
    end

    def latest_version_being_used?
      latest_bundler_version == current_bundler_version
    end

    def valid?
      unless latest_version_being_used?
        @error = %{
            Please update the bundler version on your machine to #{latest_bundler_version}
            You can follow the following steps:

            1. Install the latest bundler version:
              - gem install bundler
            2. Open Gemfile.lock of the project:
              - vim ./Gemfile.lock
            3. Delete the last line that contains the bundler version.
            4. Run:
              - bundle install

            You can also watch the following video that contains the same steps:
              - https://youtu.be/vqAUIQehbKw
          }
        return false
      end

      true
    end

    def autofix_suggestion
      @error.yellow
    end

    def autofix_command
      "gem install bundler; perl -p -i -e 's/#{current_bundler_version}(\n*)\\Z/#{latest_bundler_version}\n/m' Gemfile.lock"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
neetob-0.1.2 neeto_compliance/lib/neeto_compliance/verifiers/bundler_version_verifier.rb
neetob-0.1.1 /Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/bundler_version_verifier.rb
neetob-0.1.0 /Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/bundler_version_verifier.rb