mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00

Originally we were going to try and load the *flight blocks from the API but we ended up going with downloading the caskfile for the subset of casks that need this functionality for consisty's sake. This reverts the following commits from most recent to oldest: - ffc74a51fb32b66a4cd8bc41dbd076dd23d9100e - e5616e94fe42505434c330be35eeafef2739944f - d1490c3d5c087d00f2bca1787cce331202b195c5 - 7ca5a5d9a71a73f21bbb8555a38048f027bee89b - 2d5d132713d0701d02d5ff33e9918812d13d2a83 It also changes how *flight blocks are handled in `.to_h`. Essentially, when *flight blocks exist they are just included as a hash of the artifact to nil to indicate that they exist. More information isn't necessary since we don't evaluate the current source code in the *flight artifacts that we get from the API.
54 lines
1.2 KiB
Ruby
54 lines
1.2 KiB
Ruby
# typed: true
|
|
# frozen_string_literal: true
|
|
|
|
require "cask/artifact/abstract_artifact"
|
|
|
|
module Cask
|
|
module Artifact
|
|
# Abstract superclass for block artifacts.
|
|
#
|
|
# @api private
|
|
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
|