Sha256: a7a13525d3a8164f89351c3c87f456cc3e2f176336c172b91b9450fdb78b0c23

Contents?: true

Size: 1.56 KB

Versions: 3

Compression:

Stored size: 1.56 KB

Contents

# Exits Ruby process, only to be called from top level `carthagerc` script
def bail(message, code = 1)
  $stderr.puts(message.strip + "\n")
  Process.exit(code)
end

def crc32(filename)
  checksum = Digest::CRC32.file(filename).hexdigest
  $LOG.debug("CRC32 checksum for '#{filename}': #{checksum}")
  checksum
end

# Quote command line arguments with double quotes.
# Useful for file paths with spaces.
def quote(input)
  if input.is_a? String
    if input.empty?
      ""
    else
      '"' + input + '"'
    end
  elsif input.is_a? Array
    input
      .map { |e| quote(e) }
      .select { |e| !e.empty? }
      .join(" ")
  else
    raise AppError.new, "Unsupported type #{input}"
  end
end

def platform_to_api_string(platform)
  case platform
  when :iOS
    "iOS"
  when :macOS
    "macOS"
  when :tvOS
    "tvOS"
  when :watchOS
    "watchOS"
  else
    raise AppError.new, "Unrecognized platform #{platform.inspect}"
  end
end

def platform_to_carthage_dir_string(platform)
  case platform
  when :iOS
    "iOS"
  when :macOS
    "Mac"
  when :tvOS
    "tvOS"
  when :watchOS
    "watchOS"
  else
    raise AppError.new, "Unrecognized platform #{platform.inspect}"
  end
end

def platform_to_symbols(string)
  platforms = string.split(",").map(&:to_sym)
  for platform in platforms
    if !PLATFORMS.include?(platform)
      raise PlatformMismatchError.new(platform)
    end
  end
  platforms
end

# @return string in "x.y MB" format
def format_file_size(bytes)
  if bytes == 0
    "0.0 MB"
  else
    megabytes = [0.1, bytes / 1000.0 / 1000.0].max
    "#{megabytes.round(1)} MB"
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
carthage_remote_cache-0.0.13 lib/utils.rb
carthage_remote_cache-0.0.12 lib/utils.rb
carthage_remote_cache-0.0.11 lib/utils.rb