Class: FitCommit::Runner
- Inherits:
-
Object
- Object
- FitCommit::Runner
- 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
-
#branch_name ⇒ Object
Returns the value of attribute branch_name.
-
#message_path ⇒ Object
Returns the value of attribute message_path.
-
#stdin ⇒ Object
Returns the value of attribute stdin.
-
#stdout ⇒ Object
Returns the value of attribute stdout.
Instance Method Summary collapse
-
#initialize(message_path, branch_name, stdout = $stdout, stdin = $stdin) ⇒ Runner
constructor
A new instance of Runner.
- #run ⇒ Object
Methods included from HasErrors
#add_error, #add_warning, #errors, #merge_errors, #merge_warnings, #warnings
Constructor Details
#initialize(message_path, branch_name, stdout = $stdout, stdin = $stdin) ⇒ Runner
Returns a new instance of Runner.
12 13 14 15 16 17 |
# File 'lib/fit-commit/runner.rb', line 12 def initialize(, branch_name, stdout = $stdout, stdin = $stdin) self. = self.branch_name = branch_name self.stdout = stdout self.stdin = stdin end |
Instance Attribute Details
#branch_name ⇒ Object
Returns the value of attribute branch_name.
11 12 13 |
# File 'lib/fit-commit/runner.rb', line 11 def branch_name @branch_name end |
#message_path ⇒ Object
Returns the value of attribute message_path.
11 12 13 |
# File 'lib/fit-commit/runner.rb', line 11 def @message_path end |
#stdin ⇒ Object
Returns the value of attribute stdin.
11 12 13 |
# File 'lib/fit-commit/runner.rb', line 11 def stdin @stdin end |
#stdout ⇒ Object
Returns the value of attribute stdout.
11 12 13 |
# File 'lib/fit-commit/runner.rb', line 11 def stdout @stdout end |
Instance Method Details
#run ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fit-commit/runner.rb', line 19 def run return EXIT_CODE_ALLOW_COMMIT if empty_commit? run_validators return EXIT_CODE_ALLOW_COMMIT if [errors, warnings].all?(&:empty?) print_results allow_commit = errors.empty? unless allow_commit stdout.print "\nForce commit? [y/n] " return EXIT_CODE_REJECT_COMMIT unless stdin.gets =~ /y/i allow_commit = true end stdout.print "\n" allow_commit ? EXIT_CODE_ALLOW_COMMIT : EXIT_CODE_REJECT_COMMIT rescue Interrupt # Ctrl-c EXIT_CODE_REJECT_COMMIT end |