Sha256: b61e815fd12cc4653bc455544e4ceebd342875c75c22eb5b86293c9876228356

Contents?: true

Size: 1.25 KB

Versions: 6

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module Capistrano
  module DataPlaneApi
    module Deploy
      # A module which provides some generic helper methods used
      # in the deployment script.
      module Helper
        extend self

        # @param seconds [Integer]
        # @return [String]
        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

        # Calculate how many seconds have passed
        # since the given point in time.
        #
        # @param time [Time]
        # @param to [Time]
        # @return [Integer]
        def seconds_since(time, to: ::Time.now)
          (to - time).to_i
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
capistrano-data_plane_api-0.1.5 lib/capistrano/data_plane_api/deploy/helper.rb
capistrano-data_plane_api-0.1.4 lib/capistrano/data_plane_api/deploy/helper.rb
capistrano-data_plane_api-0.1.3 lib/capistrano/data_plane_api/deploy/helper.rb
capistrano-data_plane_api-0.1.2 lib/capistrano/data_plane_api/deploy/helper.rb
capistrano-data_plane_api-0.1.1 lib/capistrano/data_plane_api/deploy/helper.rb
capistrano-data_plane_api-0.1.0 lib/capistrano/data_plane_api/deploy/helper.rb