Class: Overcommit::MessageProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/overcommit/message_processor.rb

Overview

Utility class that encapsulates the handling of hook messages and whether they affect lines the user has modified or not.

This class exposes an endpoint that extracts an appropriate hook/status output tuple from an array of Hook::Messages, respecting the configuration settings for the given hook.

Constant Summary collapse

ERRORS_MODIFIED_HEADER =
'Errors on modified lines:'
WARNINGS_MODIFIED_HEADER =
'Warnings on modified lines:'
ERRORS_UNMODIFIED_HEADER =
"Errors on lines you didn't modify:"
WARNINGS_UNMODIFIED_HEADER =
"Warnings on lines you didn't modify:"
ERRORS_GENERIC_HEADER =
'Errors:'
WARNINGS_GENERIC_HEADER =
'Warnings:'

Instance Method Summary collapse

Constructor Details

#initialize(hook, unmodified_lines_setting) ⇒ MessageProcessor

Returns a new instance of MessageProcessor.

Parameters:

  • hook (Overcommit::Hook::Base)
  • unmodified_lines_setting (String)

    how to treat messages on unmodified lines



21
22
23
24
# File 'lib/overcommit/message_processor.rb', line 21

def initialize(hook, unmodified_lines_setting)
  @hook = hook
  @setting = unmodified_lines_setting
end

Instance Method Details

#hook_result(messages) ⇒ Array<Symbol,String>

Returns a hook status/output tuple from the messages this processor was initialized with.

Returns:

  • (Array<Symbol,String>)


30
31
32
33
34
35
36
37
38
39
40
# File 'lib/overcommit/message_processor.rb', line 30

def hook_result(messages)
  status, output = basic_status_and_output(messages)

  # Nothing to do if there are no problems to begin with
  return [status, output] if status == :pass

  # Return as-is if this type of hook doesn't have the concept of modified lines
  return [status, output] unless @hook.respond_to?(:modified_lines_in_file)

  handle_modified_lines(messages, status)
end