Module: Depot::Util

Defined in:
lib/depot/util.rb

Class Method Summary collapse

Class Method Details

.desktop_exec_quote(path) ⇒ Object



29
30
31
# File 'lib/depot/util.rb', line 29

def desktop_exec_quote(path)
  %("#{path.gsub(/(["\\`$])/, '\\\\\\1')}")
end

.sha256(path) ⇒ Object



9
10
11
# File 'lib/depot/util.rb', line 9

def sha256(path)
  Digest::SHA256.file(path).hexdigest
end

.slug(value) ⇒ Object



13
14
15
16
17
# File 'lib/depot/util.rb', line 13

def slug(value)
  base = File.basename(value.to_s, ".*").downcase
  base = base.gsub(/[^a-z0-9]+/, "-").gsub(/\A-+|-+\z/, "")
  base.empty? ? "app" : base
end

.unique_id(base, taken) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/depot/util.rb', line 19

def unique_id(base, taken)
  candidate = base
  index = 2
  while taken.include?(candidate)
    candidate = "#{base}-#{index}"
    index += 1
  end
  candidate
end