Class: SpaceArchitect::CLI::RepoProgress
- Inherits:
-
Object
- Object
- SpaceArchitect::CLI::RepoProgress
- Defined in:
- lib/space_architect/cli/helpers.rb
Instance Method Summary collapse
- #fail(addition) ⇒ Object
- #finish(addition) ⇒ Object
-
#initialize(total) ⇒ RepoProgress
constructor
A new instance of RepoProgress.
- #message ⇒ Object
- #start(addition) ⇒ Object
- #trust(addition) ⇒ Object
Constructor Details
#initialize(total) ⇒ RepoProgress
Returns a new instance of RepoProgress.
66 67 68 69 |
# File 'lib/space_architect/cli/helpers.rb', line 66 def initialize(total) @total = total @statuses = {} end |
Instance Method Details
#fail(addition) ⇒ Object
84 85 86 |
# File 'lib/space_architect/cli/helpers.rb', line 84 def fail(addition) @statuses[addition.fetch(:reference).full_name] = :failed end |
#finish(addition) ⇒ Object
80 81 82 |
# File 'lib/space_architect/cli/helpers.rb', line 80 def finish(addition) @statuses[addition.fetch(:reference).full_name] = :done end |
#message ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/space_architect/cli/helpers.rb', line 88 def done = @statuses.count { |_repo, status| status == :done } failed = @statuses.count { |_repo, status| status == :failed } = @statuses.select { |_repo, status| status == :copying }.keys cloning = @statuses.select { |_repo, status| status == :cloning }.keys trusting = @statuses.select { |_repo, status| status == :trusting }.keys if @total == 1 = .first cloning_repo = cloning.first trusting_repo = trusting.first return "Copying #{}" if return "Cloning #{cloning_repo}" if cloning_repo return "Trusting #{trusting_repo}" if trusting_repo return "Fetch failed" if failed.positive? "Preparing repos" else active = [] active << "copying #{.join(', ')}" unless .empty? active << "cloning #{cloning.join(', ')}" unless cloning.empty? active << "trusting #{trusting.join(', ')}" unless trusting.empty? suffix = active.empty? ? nil : ": #{active.join('; ')}" failed_text = failed.positive? ? ", #{failed} failed" : "" "Fetching repos #{done}/#{@total}#{failed_text}#{suffix}" end end |
#start(addition) ⇒ Object
71 72 73 74 |
# File 'lib/space_architect/cli/helpers.rb', line 71 def start(addition) source = addition[:src_source] @statuses[addition.fetch(:reference).full_name] = source&.directory? ? :copying : :cloning end |
#trust(addition) ⇒ Object
76 77 78 |
# File 'lib/space_architect/cli/helpers.rb', line 76 def trust(addition) @statuses[addition.fetch(:reference).full_name] = :trusting end |