Class: Gitrob::ProgressBar

Inherits:
Object
  • Object
show all
Defined in:
lib/gitrob/progressbar.rb

Constant Summary collapse

TITLE_MAX_LENGTH =
25

Instance Method Summary collapse

Constructor Details

#initialize(message, options) ⇒ ProgressBar

Returns a new instance of ProgressBar.



7
8
9
10
11
12
13
14
15
16
# File 'lib/gitrob/progressbar.rb', line 7

def initialize(message, options)
  @options = {
    :format         => " #{Paint['[*]', :bright, :blue]} %c/%C %B %j% %e",
    :progress_mark  => Paint['▓', :bright, :blue],
    :remainder_mark => '░',
  }.merge(options)
  Gitrob::status(message)
  @mutex = Mutex.new
  @progress_bar = ::ProgressBar::Base.new(@options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/gitrob/progressbar.rb', line 34

def method_missing(method, *args, &block)
  if @progress_bar.respond_to?(method)
    @mutex.synchronize { @progress_bar.send(method, *args, &block) }
  else
    super
  end
end

Instance Method Details

#finish!Object



18
19
20
# File 'lib/gitrob/progressbar.rb', line 18

def finish!
  @mutex.synchronize { @progress_bar.finish }
end

#log(message) ⇒ Object



22
23
24
25
26
# File 'lib/gitrob/progressbar.rb', line 22

def log(message)
  @mutex.synchronize do
    @progress_bar.log(" #{Paint['[>]', :bright, :blue]} #{message}")
  end
end

#log_error(message) ⇒ Object



28
29
30
31
32
# File 'lib/gitrob/progressbar.rb', line 28

def log_error(message)
  @mutex.synchronize do
    @progress_bar.log(" #{Paint['[!]', :bright, :red]} #{message}")
  end
end