-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
/
abstract_flight_block.rb
51 lines (39 loc) 路 1.16 KB
/
abstract_flight_block.rb
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# typed: true
# frozen_string_literal: true
require "cask/artifact/abstract_artifact"
module Cask
module Artifact
# Abstract superclass for block artifacts.
class AbstractFlightBlock < AbstractArtifact
def self.dsl_key
super.to_s.sub(/_block$/, "").to_sym
end
def self.uninstall_dsl_key
dsl_key.to_s.prepend("uninstall_").to_sym
end
attr_reader :directives
def initialize(cask, **directives)
super(cask)
@directives = directives
end
def install_phase(**)
abstract_phase(self.class.dsl_key)
end
def uninstall_phase(**)
abstract_phase(self.class.uninstall_dsl_key)
end
def summarize
directives.keys.map(&:to_s).join(", ")
end
private
def class_for_dsl_key(dsl_key)
namespace = self.class.name.to_s.sub(/::.*::.*$/, "")
self.class.const_get("#{namespace}::DSL::#{dsl_key.to_s.split("_").map(&:capitalize).join}")
end
def abstract_phase(dsl_key)
return if (block = directives[dsl_key]).nil?
class_for_dsl_key(dsl_key).new(cask).instance_eval(&block)
end
end
end
end