Module: Capistrano::DataPlaneApi::Deploy::Helper

Extended by:
Helper
Included in:
Helper
Defined in:
lib/capistrano/data_plane_api/deploy/helper.rb

Overview

A module which provides some generic helper methods used in the deployment script.

Instance Method Summary collapse

Instance Method Details

#humanize_time(seconds) ⇒ String

Parameters:

  • seconds (Integer)

Returns:

  • (String)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/capistrano/data_plane_api/deploy/helper.rb', line 13

def humanize_time(seconds)
  hours = seconds / 3600
  rest_seconds = seconds - (hours * 3600)
  minutes = rest_seconds / 60
  rest_seconds = seconds - (minutes * 60)

  result = ::String.new

  if rest_seconds.positive?
    result.prepend "#{rest_seconds}s"
    styles = %i[bright_green]
  end

  if minutes.positive?
    result.prepend "#{minutes}min "
    styles = %i[bright_yellow]
  end

  if hours.positive?
    result.prepend "#{hours}h "
    styles = %i[bright_red]
  end

  COLORS.decorate(result.strip, *styles)
end

#seconds_since(time, to: ::Time.now) ⇒ Integer

Calculate how many seconds have passed since the given point in time.

Parameters:

  • time (Time)
  • to (Time) (defaults to: ::Time.now)

Returns:

  • (Integer)


45
46
47
# File 'lib/capistrano/data_plane_api/deploy/helper.rb', line 45

def seconds_since(time, to: ::Time.now)
  (to - time).to_i
end