Class: Hbc::Container::Gpg

Inherits:
Base
  • Object
show all
Defined in:
Library/Homebrew/cask/lib/hbc/container/gpg.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#extract_nested_container, #extract_nested_inside, #initialize, #verbose?

Constructor Details

This class inherits a constructor from Hbc::Container::Base

Class Method Details

.me?(criteria) ⇒ Boolean



8
9
10
# File 'Library/Homebrew/cask/lib/hbc/container/gpg.rb', line 8

def self.me?(criteria)
  criteria.extension(/^(gpg)$/)
end

Instance Method Details

#extractObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'Library/Homebrew/cask/lib/hbc/container/gpg.rb', line 26

def extract
  unless gpg = which("gpg", PATH.new(ENV["PATH"], HOMEBREW_PREFIX/"bin"))
    raise CaskError, "Expected to find gpg executable. Cask '#{@cask}' must add: depends_on formula: 'gpg'"
  end

  import_key

  Dir.mktmpdir do |unpack_dir|
    @command.run!(gpg, args: ["--batch", "--yes", "--output", Pathname(unpack_dir).join(@path.basename(".gpg")), "--decrypt", @path])

    extract_nested_inside(unpack_dir)
  end
end

#import_keyObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'Library/Homebrew/cask/lib/hbc/container/gpg.rb', line 12

def import_key
  if @cask.gpg.nil?
    raise CaskError, "Expected to find gpg public key in formula. Cask '#{@cask}' must add: 'gpg :embedded, key_id: [Public Key ID]' or 'gpg :embedded, key_url: [Public Key URL]'"
  end

  args = if @cask.gpg.key_id
    ["--recv-keys", @cask.gpg.key_id]
  elsif @cask.gpg.key_url
    ["--fetch-key", @cask.gpg.key_url.to_s]
  end

  @command.run!("gpg", args: args)
end