Class: FitCommit::Runner

Inherits:
Object
  • Object
show all
Includes:
HasErrors
Defined in:
lib/fit_commit/runner.rb

Constant Summary collapse

EXIT_CODE_ALLOW_COMMIT =
0
EXIT_CODE_REJECT_COMMIT =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HasErrors

#add_error, #add_warning, #clear_errors, #clear_warnings, #errors, #merge_errors, #merge_warnings, #warnings

Constructor Details

#initialize(message_path, branch_name, stderr = $stderr, stdin = $stdin) ⇒ Runner

Returns a new instance of Runner.



13
14
15
16
17
18
# File 'lib/fit_commit/runner.rb', line 13

def initialize(message_path, branch_name, stderr = $stderr, stdin = $stdin)
  self.message_path = message_path
  self.branch_name = branch_name
  self.stderr = stderr
  self.stdin = stdin
end

Instance Attribute Details

#branch_nameObject

Returns the value of attribute branch_name.



12
13
14
# File 'lib/fit_commit/runner.rb', line 12

def branch_name
  @branch_name
end

#message_pathObject

Returns the value of attribute message_path.



12
13
14
# File 'lib/fit_commit/runner.rb', line 12

def message_path
  @message_path
end

#stderrObject

Returns the value of attribute stderr.



12
13
14
# File 'lib/fit_commit/runner.rb', line 12

def stderr
  @stderr
end

#stdinObject

Returns the value of attribute stdin.



12
13
14
# File 'lib/fit_commit/runner.rb', line 12

def stdin
  @stdin
end

Instance Method Details

#runObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fit_commit/runner.rb', line 20

def run
  allow_commit = retry_on_user_edit do
    return EXIT_CODE_ALLOW_COMMIT if empty_commit?
    run_validators
    return EXIT_CODE_ALLOW_COMMIT if [errors, warnings].all?(&:empty?)
    print_results
    errors.empty? || ask_force_commit
  end

  if allow_commit
    stderr.print "\n"
    EXIT_CODE_ALLOW_COMMIT
  else
    EXIT_CODE_REJECT_COMMIT
  end
rescue Interrupt # Ctrl-c
  EXIT_CODE_REJECT_COMMIT
end