diff --git a/Library/Homebrew/cask/lib/hbc/artifact.rb b/Library/Homebrew/cask/lib/hbc/artifact.rb index 505f9ec134..1cbe49cf27 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact.rb @@ -25,39 +25,5 @@ require "hbc/artifact/zap" module Hbc module Artifact - # NOTE: Order is important here! - # - # The `uninstall` stanza should be run first, as it may - # depend on other artifacts still being installed. - # - # We want to extract nested containers before we - # handle any other artifacts. - # - CLASSES = [ - PreflightBlock, - Uninstall, - NestedContainer, - Installer, - App, - Suite, - Artifact, # generic 'artifact' stanza - Colorpicker, - Pkg, - Prefpane, - Qlplugin, - Dictionary, - Font, - Service, - StageOnly, - Binary, - InputMethod, - InternetPlugin, - AudioUnitPlugin, - VstPlugin, - Vst3Plugin, - ScreenSaver, - PostflightBlock, - Zap, - ].freeze end end diff --git a/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb b/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb index 331e098e01..17a778f665 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb @@ -21,34 +21,42 @@ module Hbc end def <=>(other) + return unless other.class < AbstractArtifact + return 0 if self.class == other.class + @@sort_order ||= [ # rubocop:disable Style/ClassVars PreflightBlock, + # The `uninstall` stanza should be run first, as it may + # depend on other artifacts still being installed. Uninstall, + # We want to extract nested containers before we + # handle any other artifacts. NestedContainer, Installer, - App, - Suite, - Artifact, # generic 'artifact' stanza - Colorpicker, - Pkg, - Prefpane, - Qlplugin, - Dictionary, - Font, - Service, - StageOnly, + [ + App, + Suite, + Artifact, + Colorpicker, + Prefpane, + Qlplugin, + Dictionary, + Font, + Service, + InputMethod, + InternetPlugin, + AudioUnitPlugin, + VstPlugin, + Vst3Plugin, + ScreenSaver, + ], Binary, - InputMethod, - InternetPlugin, - AudioUnitPlugin, - VstPlugin, - Vst3Plugin, - ScreenSaver, + Pkg, PostflightBlock, Zap, - ] + ].each_with_index.flat_map { |classes, i| [*classes].map { |c| [c, i] } }.to_h - (@@sort_order.index(self.class) <=> @@sort_order.index(other.class)).to_i + (@@sort_order[self.class] <=> @@sort_order[other.class]).to_i end # TODO: this sort of logic would make more sense in dsl.rb, or a