aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/lib/hbc/artifact/nested_container.rb
blob: c9fd3dc271e8561f741456a086d70fb0a1b2bd4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require "hbc/artifact/abstract_artifact"

module Hbc
  module Artifact
    class NestedContainer < AbstractArtifact
      attr_reader :path

      def initialize(cask, path)
        super(cask)
        @path = cask.staged_path.join(path)
      end

      def install_phase(**options)
        extract(**options)
      end

      private

      def summarize
        path.relative_path_from(cask.staged_path).to_s
      end

      def extract(command: nil, verbose: nil, **_)
        container = Container.for_path(path, command)

        unless container
          raise CaskError, "Aw dang, could not identify nested container at '#{source}'"
        end

        ohai "Extracting nested container #{path.relative_path_from(cask.staged_path)}"
        container.new(cask, path, command, verbose: verbose).extract
        FileUtils.remove_entry_secure(path)
      end
    end
  end
end