Class: UpdateRepo::GitControl
- Inherits:
-
Object
- Object
- UpdateRepo::GitControl
- Includes:
- Helpers
- Defined in:
- lib/update_repo/git_control.rb
Overview
Class : GitControl. This class will update one git repo, and send the output to the logger. It will also return status of the operation in #status.
Instance Attribute Summary collapse
-
#status ⇒ hash
readonly
Return the status hash.
Instance Method Summary collapse
-
#initialize(dir, logger, metrics, cmd) ⇒ void
constructor
Constructor for the GitControl class.
-
#update ⇒ void
Update the git repo that was specified in the initializer.
Methods included from Helpers
Constructor Details
#initialize(dir, logger, metrics, cmd) ⇒ void
Constructor for the GitControl class.
25 26 27 28 29 30 31 |
# File 'lib/update_repo/git_control.rb', line 25 def initialize(dir, logger, metrics, cmd) @status = { updated: false, failed: false, unchanged: false } @dir = dir @log = logger @metrics = metrics @cmd = cmd end |
Instance Attribute Details
#status ⇒ hash (readonly)
Return the status hash
15 16 17 |
# File 'lib/update_repo/git_control.rb', line 15 def status @status end |
Instance Method Details
#update ⇒ void
This method returns an undefined value.
Update the git repo that was specified in the initializer.
36 37 38 39 40 41 42 43 44 |
# File 'lib/update_repo/git_control.rb', line 36 def update print_log '* Checking ', @dir.green, " (#{repo_url})\n" Open3.popen2e("git -C #{@dir} pull") do |_stdin, stdout_err, _thread| stdout_err.each { |line| handle_output(line) } end # reset the updated status in the rare case than both update and failed # are set. This does happen! @status[:updated] = false if @status[:updated] && @status[:failed] end |