Module: Aerosol::Util

Extended by:
Util
Included in:
Util
Defined in:
lib/aerosol/util.rb

Instance Method Summary collapse

Instance Method Details

#git_repoObject



34
35
36
# File 'lib/aerosol/util.rb', line 34

def git_repo
  @git_repo ||= MiniGit.new('.')
end

#git_shaObject



38
39
40
# File 'lib/aerosol/util.rb', line 38

def git_sha
  @git_sha ||= git_repo.capturing.rev_parse('HEAD').chomp[0..6] rescue 'unknown'
end

#is_gzip?(path) ⇒ Boolean

Returns:

  • (Boolean)


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

def is_gzip?(path)
  if File.size(path) < 2
    return false
  end
  magic = nil
  File.open(path, "r") do |f|
    magic = f.read(2)
  end
  magic = magic.unpack('H*')[0]
  magic == "1f8b"
end

#is_tar?(path) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
13
14
15
16
# File 'lib/aerosol/util.rb', line 6

def is_tar?(path)
  if File.size(path) < 262
    return false
  end
  magic = nil
  File.open(path, "r") do |f|
    f.read(257)
    magic = f.read(5)
  end
  magic == "ustar"
end

#strip_heredoc(str) ⇒ Object



30
31
32
# File 'lib/aerosol/util.rb', line 30

def strip_heredoc(str)
  str.gsub(/^#{str[/\A\s*/]}/, '')
end