Sha256: 4005c55632149f685267fc3d8deb79eec65fb5f62191da71c0a14f679123c3a5

Contents?: true

Size: 840 Bytes

Versions: 5

Compression:

Stored size: 840 Bytes

Contents

# frozen_string_literal: true

module BoxtRubyStyleGuide
  # Returns a list of files that have changed, as detected by `git-diff`
  #
  # TODO: Write tests for this to ensure we're pulling the desired diff files
  # see: https://github.com/ruby-git/ruby-git
  class GitDiff
    require "git"

    ##
    # List of Git statuses we should test
    # See: https://git-scm.com/docs/git-status#_short_format
    TEST_STATUSES = %w[M A U].freeze

    attr_reader :base

    def initialize(base:)
      @base = base
    end

    ##
    # A list of the local file paths of Ruby files with committed changes.
    #
    # Returns Array
    def all
      @all ||= begin
        git.diff(base).name_status.select { |_, stat| TEST_STATUSES.include?(stat) }.keys
      end
    end

    private

    def git
      @git ||= Git.open(".")
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
boxt_ruby_style_guide-7.9.3 lib/boxt_ruby_style_guide/git_diff.rb
boxt_ruby_style_guide-7.9.2 lib/boxt_ruby_style_guide/git_diff.rb
boxt_ruby_style_guide-7.9.1 lib/boxt_ruby_style_guide/git_diff.rb
boxt_ruby_style_guide-7.9.0 lib/boxt_ruby_style_guide/git_diff.rb
boxt_ruby_style_guide-7.8.0 lib/boxt_ruby_style_guide/git_diff.rb