Module: PgVerify::Shell::LoadingPrompt

Defined in:
lib/pg-verify/shell/loading/loading_prompt.rb

Defined Under Namespace

Classes: LoadingResult

Class Method Summary collapse

Class Method Details

.while_loading(loading_message) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pg-verify/shell/loading/loading_prompt.rb', line 6

def self.while_loading(loading_message)
    if Shell.in_pipe? || !Settings.use_animations
        # Do not play animations when piped
        animation = NoAnimation.new(loading_message).start
    else
        animation = LineAnimation.new(loading_message).start
    end

    start_time = Time.now

    begin
        result = yield(animation) if block_given?
        delta_time = Time.now - start_time
    rescue StandardError, SignalException, Interrupt, IOError => e
        exception = e
    ensure
        status = exception.nil? ? (result.nil? ? :empty : :success) : :error
        status = result.state if !result.nil? && result.is_a?(LoadingResult)
        animation.stop(status, result.is_a?(LoadingResult) ? result.message : "")
        result = result.data if result.is_a?(LoadingResult)
        raise exception unless exception.nil?
    end

    return result
end