Sha256: 967f72b129c67d9440e3b8505d3327625e4f83bc4dc89c3665a62e6b38b890ee

Contents?: true

Size: 812 Bytes

Versions: 1

Compression:

Stored size: 812 Bytes

Contents

module Doggy
  module SharedHelpers
    MAX_TRIES = 5

    def self.strip_heredoc(string)
      indent = string.scan(/^[ \t]*(?=\S)/).min.try(:size) || 0
      string.gsub(/^[ \t]{#{indent}}/, '')
    end

    def self.with_retry(times: MAX_TRIES, reraise: false)
      tries = 0
      while tries < times
        begin
          yield
          break
        rescue => e
          error "Caught error! Attempt #{tries}..."
          error "#{e.class.name}: #{e.message}"
          error "#{e.backtrace.join("\n")}"
          tries += 1

          raise e if tries >= times && reraise
        end
      end
    end

    def self.agree(prompt)
      raise Error, "Not a tty" unless $stdin.tty?

      puts prompt + " (Y/N)"
      line = $stdin.readline.chomp.upcase
      puts
      line == "Y"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
doggy-0.2.0 lib/doggy/shared_helpers.rb