Sha256: 761c15c85ad85e2bf7d9bad1c67cd574db6a674d4f046017fe1c7a47d6cb13de

Contents?: true

Size: 872 Bytes

Versions: 1

Compression:

Stored size: 872 Bytes

Contents

require 'shellwords'

module RuboCop
  module Git
    # ref. https://github.com/thoughtbot/hound/blob/be2dd34/app/models/pull_request.rb
    class PseudoPullRequest
      HOUND_CONFIG_FILE = '.hound.yml'

      def initialize(files, options)
        @files = files
        @options = options
      end

      def pull_request_files
        @files.map do |file|
          build_commit_file(file)
        end
      end

      def config
        return unless @options[:hound]
        File.read(HOUND_CONFIG_FILE)
      rescue Errno::ENOENT
        nil
      end

      private

      def build_commit_file(file)
        CommitFile.new(file, file_contents(file.filename))
      end

      def file_contents(filename)
        if @options[:cached]
          `git show :#{filename.shellescape}`
        else
          File.read(filename)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-git-0.0.1 lib/rubocop/git/pseudo_pull_request.rb