class TestChanges::Client

Attributes

argv_wrapper[R]

rubocop:enable Metrics/AbcSize

runner[R]

rubocop:enable Metrics/AbcSize

Public Class Methods

new(options) click to toggle source
# File lib/test_changes/client.rb, line 3
def initialize(options)
  @argv_wrapper = options[:argv_wrapper]
  @runner = options[:runner]
end

Public Instance Methods

call() click to toggle source

rubocop:disable Metrics/AbcSize

# File lib/test_changes/client.rb, line 9
def call
  log "Paths changed since commit #{argv_wrapper.commit}:",
    paths_changed_since_commit.inspect

  log "Matches:", matches.inspect

  log "Existing matches:", existing_matches.inspect

  return if existing_matches.empty?

  log "Non-excluded matches:", included_matches.inspect

  return if included_matches.empty?

  log "Test tool call:", test_tool_call
  system(test_tool_call)
end

Private Instance Methods

existing_matches() click to toggle source
# File lib/test_changes/client.rb, line 60
def existing_matches
  @existing_matches ||= matches.select { |match| File.exist?(match) }
end
included_matches() click to toggle source
# File lib/test_changes/client.rb, line 56
def included_matches
  runner.ignore_excluded_files_service.call(existing_matches)
end
log(header, message) click to toggle source
# File lib/test_changes/client.rb, line 32
def log(header, message)
  return unless argv_wrapper.verbose?

  puts "\n#{header}"
  puts message
end
matches() click to toggle source
# File lib/test_changes/client.rb, line 64
def matches
  return @matches if @matches

  paths = paths_changed_since_commit

  @matches =
    paths.product(runner.finding_patterns).map do |path, finding_pattern|
      finding_pattern.matching_paths(path)
    end

  @matches = @matches.flatten.uniq
end
paths_changed_since_commit() click to toggle source
# File lib/test_changes/client.rb, line 43
def paths_changed_since_commit
  @paths_changed_since_commit ||=
    `git diff --name-only --diff-filter=AMR #{argv_wrapper.commit}`.split("\n")
end
test_tool_call() click to toggle source
# File lib/test_changes/client.rb, line 48
def test_tool_call
  @test_tool_call ||= [
    runner.name,
    argv_wrapper.runner_call_options,
    included_matches
  ].flatten.compact.join(' ')
end
verbose?() click to toggle source
# File lib/test_changes/client.rb, line 39
def verbose?
  verbose
end