Module: Capistrano::DataPlaneApi::Deploy::Helper
Overview
A module which provides some generic helper methods used in the deployment script.
Instance Method Summary collapse
-
#humanize_time(seconds) ⇒ Object
: (Integer) -> String.
-
#seconds_since(time, to: ::Time.now) ⇒ Object
Calculate how many seconds have passed since the given point in time.
Instance Method Details
#humanize_time(seconds) ⇒ Object
: (Integer) -> 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) ⇒ Object
Calculate how many seconds have passed since the given point in time.
: (Time, Time) -> Integer
43 44 45 |
# File 'lib/capistrano/data_plane_api/deploy/helper.rb', line 43 def seconds_since(time, to: ::Time.now) (to - time).to_i end |