Sha256: 347e5fe3a72e8089bdb1fe94068006fc89d5f8fb404001eb814a07fcf4593109

Contents?: true

Size: 951 Bytes

Versions: 4

Compression:

Stored size: 951 Bytes

Contents

module Gemdiff
  class GemUpdater
    attr_accessor :name

    def initialize(name)
      @name = name
    end

    def update
      bundle_update
    end

    def diff
      git_diff
    end

    def show
      git_show
    end

    def commit
      git_commit
    end

    def reset
      git_reset
    end

  private

    def git_show
      `git show`
    end

    def git_diff
      `git diff`
    end

    def git_commit
      added = git_changed_line
      return false if added.empty?
      version = added.split(' ').last.gsub(/[()]/, '')
      git_add_and_commit_lockfile version
      true
    end

    def git_changed_line
      `git diff | grep #{name} | grep '+  '`
    end

    def git_add_and_commit_lockfile(version)
      `git add Gemfile.lock && git commit -m 'Update #{name} to #{version}'`
    end

    def git_reset
      `git checkout Gemfile.lock`
    end

    def bundle_update
      `bundle update #{name}`
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gemdiff-0.5.0 lib/gemdiff/gem_updater.rb
gemdiff-0.4.2 lib/gemdiff/gem_updater.rb
gemdiff-0.4.1 lib/gemdiff/gem_updater.rb
gemdiff-0.4.0 lib/gemdiff/gem_updater.rb