Module: Mothership::Progress

Includes:
Pretty
Defined in:
lib/mothership/progress.rb

Defined Under Namespace

Modules: Dots Classes: Skipper

Constant Summary

Constants included from Pretty

Mothership::Pretty::COLOR_CODES, Mothership::Pretty::DEFAULT_COLORS, Mothership::Pretty::WINDOWS

Instance Method Summary collapse

Instance Method Details

#quiet?Boolean

override to determine whether to show progress

Returns:

  • (Boolean)


77
78
79
# File 'lib/mothership/progress.rb', line 77

def quiet?
  false
end

#with_progress(message) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/mothership/progress.rb', line 81

def with_progress(message)
  unless quiet?
    print message
    Dots.start!
  end

  skipper = Skipper.new do |status, color, callback|
    unless quiet?
      Dots.stop!
      puts "... #{c(status, color)}"
    end

    return callback && callback.call
  end

  begin
    res = yield skipper
    unless quiet?
      Dots.stop!
      puts "... #{c("OK", :good)}"
    end
    res
  rescue
    unless quiet?
      Dots.stop!
      puts "... #{c("FAILED", :error)}"
    end

    raise
  end
end