aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/lib/hbc/artifact/artifact.rb
blob: b7df4b0bd0f24b248ec2b1583687894eae5c3b93 (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
37
require "hbc/artifact/moved"

require "hbc/utils/hash_validator"

module Hbc
  module Artifact
    class Artifact < Moved
      def self.english_name
        "Generic Artifact"
      end

      def self.from_args(cask, *args)
        source_string, target_hash = args

        if source_string.nil?
          raise CaskInvalidError.new(cask.token, "no source given for #{english_name}")
        end

        unless target_hash.is_a?(Hash)
          raise CaskInvalidError.new(cask.token, "target required for #{english_name} '#{source_string}'")
        end

        target_hash.extend(HashValidator).assert_valid_keys(:target)

        new(cask, source_string, **target_hash)
      end

      def resolve_target(target)
        Pathname(target)
      end

      def initialize(cask, source, target: nil)
        super(cask, source, target: target)
      end
    end
  end
end