| 
									
										
										
										
											2024-08-12 10:30:59 +01:00
										 |  |  | # typed: true # rubocop:todo Sorbet/StrictSigil | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-28 11:45:18 -08:00
										 |  |  | require "attrable" | 
					
						
							| 
									
										
										
										
											2024-03-05 17:11:55 +00:00
										 |  |  | require "bundle_version" | 
					
						
							| 
									
										
										
										
											2018-09-03 19:39:07 +01:00
										 |  |  | require "cask/cask_loader" | 
					
						
							|  |  |  | require "cask/config" | 
					
						
							|  |  |  | require "cask/dsl" | 
					
						
							|  |  |  | require "cask/metadata" | 
					
						
							| 
									
										
										
										
											2024-06-22 13:31:50 -04:00
										 |  |  | require "cask/tab" | 
					
						
							| 
									
										
										
										
											2022-06-23 17:19:27 -04:00
										 |  |  | require "utils/bottles" | 
					
						
							| 
									
										
										
										
											2023-03-21 19:05:41 -07:00
										 |  |  | require "extend/api_hashable" | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  | module Cask | 
					
						
							| 
									
										
										
										
											2020-08-24 22:50:21 +02:00
										 |  |  |   # An instance of a cask. | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |   class Cask | 
					
						
							|  |  |  |     extend Forwardable | 
					
						
							| 
									
										
										
										
											2023-12-28 11:45:18 -08:00
										 |  |  |     extend Attrable | 
					
						
							| 
									
										
										
										
											2023-03-21 19:05:41 -07:00
										 |  |  |     extend APIHashable | 
					
						
							| 
									
										
										
										
											2017-04-20 10:48:32 +02:00
										 |  |  |     include Metadata | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-22 21:05:48 +02:00
										 |  |  |     # The token of this {Cask}. | 
					
						
							|  |  |  |     # | 
					
						
							| 
									
										
										
										
											2024-04-22 21:22:22 +02:00
										 |  |  |     # @api internal | 
					
						
							| 
									
										
										
										
											2024-04-22 21:05:48 +02:00
										 |  |  |     attr_reader :token | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # The configuration of this {Cask}. | 
					
						
							|  |  |  |     # | 
					
						
							|  |  |  |     # @api internal | 
					
						
							|  |  |  |     attr_reader :config | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     attr_reader :sourcefile_path, :source, :default_config, :loader | 
					
						
							| 
									
										
										
										
											2022-06-12 15:27:31 -04:00
										 |  |  |     attr_accessor :download, :allow_reassignment | 
					
						
							| 
									
										
										
										
											2022-05-07 20:19:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-18 12:08:54 -08:00
										 |  |  |     attr_predicate :loaded_from_api? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-21 21:55:16 -08:00
										 |  |  |     def self.all(eval_all: false) | 
					
						
							|  |  |  |       if !eval_all && !Homebrew::EnvConfig.eval_all? | 
					
						
							| 
									
										
										
										
											2024-02-04 15:19:29 +01:00
										 |  |  |         raise ArgumentError, "Cask::Cask#all cannot be used without `--eval-all` or HOMEBREW_EVAL_ALL" | 
					
						
							| 
									
										
										
										
											2023-02-07 19:25:51 +01:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2022-09-05 13:57:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-21 21:39:58 -08:00
										 |  |  |       # Load core casks from tokens so they load from the API when the core cask is not tapped. | 
					
						
							|  |  |  |       tokens_and_files = CoreCaskTap.instance.cask_tokens | 
					
						
							|  |  |  |       tokens_and_files += Tap.reject(&:core_cask_tap?).flat_map(&:cask_files) | 
					
						
							| 
									
										
										
										
											2024-02-22 23:29:55 +00:00
										 |  |  |       tokens_and_files.filter_map do |token_or_file| | 
					
						
							| 
									
										
										
										
											2023-12-21 21:39:58 -08:00
										 |  |  |         CaskLoader.load(token_or_file) | 
					
						
							| 
									
										
										
										
											2019-10-13 10:03:26 +01:00
										 |  |  |       rescue CaskUnreadableError => e | 
					
						
							|  |  |  |         opoo e.message | 
					
						
							| 
									
										
										
										
											2022-01-03 14:59:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         nil | 
					
						
							| 
									
										
										
										
											2024-02-22 23:29:55 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2018-04-14 10:28:28 +02:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-29 16:27:54 +02:00
										 |  |  |     def tap | 
					
						
							|  |  |  |       return super if block_given? # Object#tap | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-29 16:27:54 +02:00
										 |  |  |       @tap | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-12 17:06:29 -07:00
										 |  |  |     sig { | 
					
						
							|  |  |  |       params( | 
					
						
							|  |  |  |         token:              String, | 
					
						
							|  |  |  |         sourcefile_path:    T.nilable(Pathname), | 
					
						
							|  |  |  |         source:             T.nilable(String), | 
					
						
							|  |  |  |         tap:                T.nilable(Tap), | 
					
						
							|  |  |  |         loaded_from_api:    T::Boolean, | 
					
						
							|  |  |  |         config:             T.nilable(Config), | 
					
						
							|  |  |  |         allow_reassignment: T::Boolean, | 
					
						
							|  |  |  |         loader:             T.nilable(CaskLoader::ILoader), | 
					
						
							|  |  |  |         block:              T.nilable(T.proc.bind(DSL).void), | 
					
						
							|  |  |  |       ).void | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-02-18 12:08:54 -08:00
										 |  |  |     def initialize(token, sourcefile_path: nil, source: nil, tap: nil, loaded_from_api: false, | 
					
						
							| 
									
										
										
										
											2023-02-25 02:08:39 -08:00
										 |  |  |                    config: nil, allow_reassignment: false, loader: nil, &block) | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       @token = token | 
					
						
							|  |  |  |       @sourcefile_path = sourcefile_path | 
					
						
							| 
									
										
										
										
											2021-08-14 16:18:13 -04:00
										 |  |  |       @source = source | 
					
						
							| 
									
										
										
										
											2017-07-29 16:27:54 +02:00
										 |  |  |       @tap = tap | 
					
						
							| 
									
										
										
										
											2022-06-12 15:27:31 -04:00
										 |  |  |       @allow_reassignment = allow_reassignment | 
					
						
							| 
									
										
										
										
											2023-02-18 12:08:54 -08:00
										 |  |  |       @loaded_from_api = loaded_from_api | 
					
						
							| 
									
										
										
										
											2023-02-14 14:19:40 +00:00
										 |  |  |       @loader = loader | 
					
						
							| 
									
										
										
										
											2024-04-26 20:55:51 +02:00
										 |  |  |       # Sorbet has trouble with bound procs assigned to instance variables: | 
					
						
							|  |  |  |       # https://github.com/sorbet/sorbet/issues/6843 | 
					
						
							| 
									
										
										
										
											2023-03-12 17:06:29 -07:00
										 |  |  |       instance_variable_set(:@block, block) | 
					
						
							| 
									
										
										
										
											2020-09-29 23:46:30 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       @default_config = config || Config.new | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       self.config = if config_path.exist? | 
					
						
							| 
									
										
										
										
											2021-01-12 16:05:06 +01:00
										 |  |  |         Config.from_json(File.read(config_path), ignore_invalid_keys: true) | 
					
						
							| 
									
										
										
										
											2020-09-29 23:46:30 +02:00
										 |  |  |       else | 
					
						
							|  |  |  |         @default_config | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2019-02-03 13:03:16 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |     # An old name for the cask. | 
					
						
							|  |  |  |     sig { returns(T::Array[String]) } | 
					
						
							|  |  |  |     def old_tokens | 
					
						
							| 
									
										
										
										
											2024-02-13 06:03:10 +01:00
										 |  |  |       @old_tokens ||= if (tap = self.tap) | 
					
						
							| 
									
										
										
										
											2024-03-08 23:36:50 -08:00
										 |  |  |         Tap.tap_migration_oldnames(tap, token) + | 
					
						
							| 
									
										
										
										
											2024-02-23 15:04:40 +01:00
										 |  |  |           tap.cask_reverse_renames.fetch(token, []) | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |       else | 
					
						
							|  |  |  |         [] | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-03 13:03:16 +01:00
										 |  |  |     def config=(config) | 
					
						
							| 
									
										
										
										
											2017-12-03 21:21:31 +01:00
										 |  |  |       @config = config | 
					
						
							| 
									
										
										
										
											2019-02-03 13:03:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-23 17:19:27 -04:00
										 |  |  |       refresh | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def refresh | 
					
						
							| 
									
										
										
										
											2017-04-06 00:33:31 +02:00
										 |  |  |       @dsl = DSL.new(self) | 
					
						
							| 
									
										
										
										
											2019-02-03 13:03:16 +01:00
										 |  |  |       return unless @block | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-03 13:03:16 +01:00
										 |  |  |       @dsl.instance_eval(&@block) | 
					
						
							| 
									
										
										
										
											2016-10-23 14:26:17 +02:00
										 |  |  |       @dsl.language_eval | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-07 18:55:13 -07:00
										 |  |  |     ::Cask::DSL::DSL_METHODS.each do |method_name| | 
					
						
							| 
									
										
										
										
											2024-10-07 22:04:24 +11:00
										 |  |  |       define_method(method_name) { |*args, &block| @dsl.send(method_name, *args, &block) } | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |     sig { params(caskroom_path: Pathname).returns(T::Array[[String, String]]) } | 
					
						
							|  |  |  |     def timestamped_versions(caskroom_path: self.caskroom_path) | 
					
						
							|  |  |  |       relative_paths = Pathname.glob(metadata_timestamped_path( | 
					
						
							|  |  |  |                                        version: "*", timestamp: "*", | 
					
						
							| 
									
										
										
										
											2024-03-07 16:20:20 +00:00
										 |  |  |                                        caskroom_path: | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |                                      )) | 
					
						
							| 
									
										
										
										
											2023-03-12 17:06:29 -07:00
										 |  |  |                                .map { |p| p.relative_path_from(p.parent.parent) } | 
					
						
							| 
									
										
										
										
											2023-03-13 09:08:51 -07:00
										 |  |  |       # Sorbet is unaware that Pathname is sortable: https://github.com/sorbet/sorbet/issues/6844 | 
					
						
							| 
									
										
										
										
											2023-03-12 17:06:29 -07:00
										 |  |  |       T.unsafe(relative_paths).sort_by(&:basename) # sort by timestamp | 
					
						
							|  |  |  |        .map { |p| p.split.map(&:to_s) } | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-22 21:05:48 +02:00
										 |  |  |     # The fully-qualified token of this {Cask}. | 
					
						
							|  |  |  |     # | 
					
						
							| 
									
										
										
										
											2024-04-22 21:22:22 +02:00
										 |  |  |     # @api internal | 
					
						
							| 
									
										
										
										
											2024-04-22 21:05:48 +02:00
										 |  |  |     def full_token | 
					
						
							| 
									
										
										
										
											2018-04-14 11:32:29 +02:00
										 |  |  |       return token if tap.nil? | 
					
						
							| 
									
										
										
										
											2023-12-13 13:17:12 +00:00
										 |  |  |       return token if tap.core_cask_tap? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-14 11:32:29 +02:00
										 |  |  |       "#{tap.name}/#{token}" | 
					
						
							| 
									
										
										
										
											2017-07-08 19:33:44 -07:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-22 21:05:48 +02:00
										 |  |  |     # Alias for {#full_token}. | 
					
						
							|  |  |  |     # | 
					
						
							|  |  |  |     # @api internal | 
					
						
							|  |  |  |     def full_name = full_token | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |     sig { returns(T::Boolean) } | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |     def installed? | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |       installed_caskfile&.exist? || false | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-25 02:08:39 -08:00
										 |  |  |     # The caskfile is needed during installation when there are | 
					
						
							|  |  |  |     # `*flight` blocks or the cask has multiple languages | 
					
						
							|  |  |  |     def caskfile_only? | 
					
						
							|  |  |  |       languages.any? || artifacts.any?(Artifact::AbstractFlightBlock) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-22 13:31:50 -04:00
										 |  |  |     def uninstall_flight_blocks? | 
					
						
							|  |  |  |       artifacts.any? do |artifact| | 
					
						
							| 
									
										
										
										
											2024-07-09 13:16:07 -04:00
										 |  |  |         case artifact | 
					
						
							|  |  |  |         when Artifact::PreflightBlock | 
					
						
							|  |  |  |           artifact.directives.key?(:uninstall_preflight) | 
					
						
							|  |  |  |         when Artifact::PostflightBlock | 
					
						
							|  |  |  |           artifact.directives.key?(:uninstall_postflight) | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2024-06-22 13:31:50 -04:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     sig { returns(T.nilable(Time)) } | 
					
						
							| 
									
										
										
										
											2019-05-31 20:38:28 +02:00
										 |  |  |     def install_time | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |       # <caskroom_path>/.metadata/<version>/<timestamp>/Casks/<token>.{rb,json} -> <timestamp> | 
					
						
							| 
									
										
										
										
											2024-11-02 15:03:10 -07:00
										 |  |  |       caskfile = installed_caskfile | 
					
						
							| 
									
										
										
										
											2024-11-03 08:58:14 -08:00
										 |  |  |       Time.strptime(caskfile.dirname.dirname.basename.to_s, Metadata::TIMESTAMP_FORMAT) if caskfile | 
					
						
							| 
									
										
										
										
											2019-05-31 20:38:28 +02:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |     sig { returns(T.nilable(Pathname)) } | 
					
						
							| 
									
										
										
										
											2017-03-12 21:59:13 +01:00
										 |  |  |     def installed_caskfile | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |       installed_caskroom_path = caskroom_path | 
					
						
							|  |  |  |       installed_token = token | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # Check if the cask is installed with an old name. | 
					
						
							|  |  |  |       old_tokens.each do |old_token| | 
					
						
							|  |  |  |         old_caskroom_path = Caskroom.path/old_token | 
					
						
							|  |  |  |         next if !old_caskroom_path.directory? || old_caskroom_path.symlink? | 
					
						
							| 
									
										
										
										
											2023-02-05 12:22:08 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         installed_caskroom_path = old_caskroom_path | 
					
						
							|  |  |  |         installed_token = old_token | 
					
						
							|  |  |  |         break | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       installed_version = timestamped_versions(caskroom_path: installed_caskroom_path).last | 
					
						
							|  |  |  |       return unless installed_version | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       caskfile_dir = metadata_main_container_path(caskroom_path: installed_caskroom_path) | 
					
						
							|  |  |  |                      .join(*installed_version, "Casks") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       ["json", "rb"] | 
					
						
							|  |  |  |         .map { |ext| caskfile_dir.join("#{installed_token}.#{ext}") } | 
					
						
							|  |  |  |         .find(&:exist?) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sig { returns(T.nilable(String)) } | 
					
						
							|  |  |  |     def installed_version | 
					
						
							| 
									
										
										
										
											2024-03-05 17:11:55 +00:00
										 |  |  |       return unless (installed_caskfile = self.installed_caskfile) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |       # <caskroom_path>/.metadata/<version>/<timestamp>/Casks/<token>.{rb,json} -> <version> | 
					
						
							| 
									
										
										
										
											2024-03-05 17:11:55 +00:00
										 |  |  |       installed_caskfile.dirname.dirname.dirname.basename.to_s | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sig { returns(T.nilable(String)) } | 
					
						
							|  |  |  |     def bundle_short_version | 
					
						
							|  |  |  |       bundle_version&.short_version | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sig { returns(T.nilable(String)) } | 
					
						
							|  |  |  |     def bundle_long_version | 
					
						
							|  |  |  |       bundle_version&.version | 
					
						
							| 
									
										
										
										
											2017-03-12 21:59:13 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-22 13:31:50 -04:00
										 |  |  |     def tab | 
					
						
							|  |  |  |       Tab.for_cask(self) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-02 17:11:37 +01:00
										 |  |  |     def config_path | 
					
						
							| 
									
										
										
										
											2021-07-06 23:48:26 +05:30
										 |  |  |       metadata_main_container_path/"config.json" | 
					
						
							| 
									
										
										
										
											2019-02-02 17:11:37 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-31 10:44:34 -07:00
										 |  |  |     def checksumable? | 
					
						
							| 
									
										
										
										
											2024-08-23 16:39:23 +01:00
										 |  |  |       return false if (url = self.url).nil? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-12 11:24:50 -04:00
										 |  |  |       DownloadStrategyDetector.detect(url.to_s, url.using) <= AbstractFileDownloadStrategy | 
					
						
							| 
									
										
										
										
											2022-05-31 10:44:34 -07:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-07 20:19:54 -07:00
										 |  |  |     def download_sha_path | 
					
						
							|  |  |  |       metadata_main_container_path/"LATEST_DOWNLOAD_SHA256" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def new_download_sha | 
					
						
							|  |  |  |       require "cask/installer" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-31 10:44:34 -07:00
										 |  |  |       # Call checksumable? before hashing | 
					
						
							| 
									
										
										
										
											2022-05-07 20:19:54 -07:00
										 |  |  |       @new_download_sha ||= Installer.new(self, verify_download_integrity: false) | 
					
						
							|  |  |  |                                      .download(quiet: true) | 
					
						
							|  |  |  |                                      .instance_eval { |x| Digest::SHA256.file(x).hexdigest } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def outdated_download_sha? | 
					
						
							| 
									
										
										
										
											2022-05-31 10:44:34 -07:00
										 |  |  |       return true unless checksumable? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-07 20:19:54 -07:00
										 |  |  |       current_download_sha = download_sha_path.read if download_sha_path.exist? | 
					
						
							|  |  |  |       current_download_sha.blank? || current_download_sha != new_download_sha | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |     sig { returns(Pathname) } | 
					
						
							| 
									
										
										
										
											2019-02-03 13:03:16 +01:00
										 |  |  |     def caskroom_path | 
					
						
							|  |  |  |       @caskroom_path ||= Caskroom.path.join(token) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-22 21:05:48 +02:00
										 |  |  |     # Check if the installed cask is outdated. | 
					
						
							|  |  |  |     # | 
					
						
							|  |  |  |     # @api internal | 
					
						
							| 
									
										
										
										
											2021-07-01 23:01:22 +10:00
										 |  |  |     def outdated?(greedy: false, greedy_latest: false, greedy_auto_updates: false) | 
					
						
							| 
									
										
										
										
											2024-03-07 16:20:20 +00:00
										 |  |  |       !outdated_version(greedy:, greedy_latest:, | 
					
						
							|  |  |  |                         greedy_auto_updates:).nil? | 
					
						
							| 
									
										
										
										
											2017-02-27 22:33:34 +02:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-19 22:09:01 +09:00
										 |  |  |     def outdated_version(greedy: false, greedy_latest: false, greedy_auto_updates: false) | 
					
						
							| 
									
										
										
										
											2017-02-27 22:33:34 +02:00
										 |  |  |       # special case: tap version is not available | 
					
						
							| 
									
										
										
										
											2023-06-19 22:09:01 +09:00
										 |  |  |       return if version.nil? | 
					
						
							| 
									
										
										
										
											2017-02-27 22:33:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-14 17:19:29 -04:00
										 |  |  |       if version.latest? | 
					
						
							| 
									
										
										
										
											2023-06-19 22:09:01 +09:00
										 |  |  |         return installed_version if (greedy || greedy_latest) && outdated_download_sha? | 
					
						
							| 
									
										
										
										
											2022-05-07 20:19:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-19 22:09:01 +09:00
										 |  |  |         return | 
					
						
							| 
									
										
										
										
											2022-05-28 10:14:51 +10:00
										 |  |  |       elsif auto_updates && !greedy && !greedy_auto_updates | 
					
						
							| 
									
										
										
										
											2023-06-19 22:09:01 +09:00
										 |  |  |         return | 
					
						
							| 
									
										
										
										
											2022-05-07 20:19:54 -07:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-27 22:33:34 +02:00
										 |  |  |       # not outdated unless there is a different version on tap | 
					
						
							| 
									
										
										
										
											2023-06-19 22:09:01 +09:00
										 |  |  |       return if installed_version == version | 
					
						
							| 
									
										
										
										
											2017-02-27 22:33:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-19 22:09:01 +09:00
										 |  |  |       installed_version | 
					
						
							| 
									
										
										
										
											2017-02-27 22:33:34 +02:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-01 23:01:22 +10:00
										 |  |  |     def outdated_info(greedy, verbose, json, greedy_latest, greedy_auto_updates) | 
					
						
							| 
									
										
										
										
											2020-04-29 18:16:39 +08:00
										 |  |  |       return token if !verbose && !json | 
					
						
							| 
									
										
										
										
											2020-04-28 12:21:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-07 16:20:20 +00:00
										 |  |  |       installed_version = outdated_version(greedy:, greedy_latest:, | 
					
						
							|  |  |  |                                            greedy_auto_updates:).to_s | 
					
						
							| 
									
										
										
										
											2020-04-28 12:21:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-26 21:07:42 +08:00
										 |  |  |       if json | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2020-04-26 21:31:21 +08:00
										 |  |  |           name:               token, | 
					
						
							| 
									
										
										
										
											2023-06-19 22:09:01 +09:00
										 |  |  |           installed_versions: [installed_version], | 
					
						
							| 
									
										
										
										
											2020-04-26 21:31:21 +08:00
										 |  |  |           current_version:    version, | 
					
						
							| 
									
										
										
										
											2020-04-26 21:07:42 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |       else | 
					
						
							| 
									
										
										
										
											2023-06-19 22:09:01 +09:00
										 |  |  |         "#{token} (#{installed_version}) != #{version}" | 
					
						
							| 
									
										
										
										
											2020-04-26 21:07:42 +08:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-07 14:06:47 +02:00
										 |  |  |     def ruby_source_path | 
					
						
							|  |  |  |       return @ruby_source_path if defined?(@ruby_source_path) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       return unless sourcefile_path | 
					
						
							|  |  |  |       return unless tap | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       @ruby_source_path = sourcefile_path.relative_path_from(tap.path) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-19 15:59:35 +00:00
										 |  |  |     sig { returns(T::Hash[Symbol, String]) } | 
					
						
							| 
									
										
										
										
											2023-02-25 02:08:39 -08:00
										 |  |  |     def ruby_source_checksum | 
					
						
							|  |  |  |       @ruby_source_checksum ||= { | 
					
						
							| 
									
										
										
										
											2024-03-02 15:01:49 -08:00
										 |  |  |         sha256: Digest::SHA256.file(sourcefile_path).hexdigest, | 
					
						
							| 
									
										
										
										
											2023-02-25 02:08:39 -08:00
										 |  |  |       }.freeze | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def languages | 
					
						
							|  |  |  |       @languages ||= @dsl.languages | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def tap_git_head | 
					
						
							|  |  |  |       @tap_git_head ||= tap&.git_head | 
					
						
							| 
									
										
										
										
											2024-07-15 13:47:21 -04:00
										 |  |  |     rescue TapUnavailableError | 
					
						
							|  |  |  |       nil | 
					
						
							| 
									
										
										
										
											2023-02-25 02:08:39 -08:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def populate_from_api!(json_cask) | 
					
						
							| 
									
										
										
										
											2023-02-18 12:08:54 -08:00
										 |  |  |       raise ArgumentError, "Expected cask to be loaded from the API" unless loaded_from_api? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-01 19:10:48 -08:00
										 |  |  |       @languages = json_cask.fetch(:languages, []) | 
					
						
							| 
									
										
										
										
											2023-04-07 14:06:47 +02:00
										 |  |  |       @tap_git_head = json_cask.fetch(:tap_git_head, "HEAD") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       @ruby_source_path = json_cask[:ruby_source_path] | 
					
						
							| 
									
										
										
										
											2024-03-02 15:01:49 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       # TODO: Clean this up when we deprecate the current JSON API and move to the internal JSON v3. | 
					
						
							|  |  |  |       ruby_source_sha256 = json_cask.dig(:ruby_source_checksum, :sha256) | 
					
						
							|  |  |  |       ruby_source_sha256 ||= json_cask[:ruby_source_sha256] | 
					
						
							| 
									
										
										
										
											2024-03-19 15:59:35 +00:00
										 |  |  |       @ruby_source_checksum = { sha256: ruby_source_sha256 } | 
					
						
							| 
									
										
										
										
											2023-02-25 02:08:39 -08:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 14:04:55 +02:00
										 |  |  |     # @api public | 
					
						
							|  |  |  |     sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2024-04-22 21:05:48 +02:00
										 |  |  |     def to_s = token | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 13:20:05 +02:00
										 |  |  |     sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2023-05-15 10:17:17 +02:00
										 |  |  |     def inspect | 
					
						
							|  |  |  |       "#<Cask #{token}#{sourcefile_path&.to_s&.prepend(" ")}>" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-28 17:53:59 +02:00
										 |  |  |     def hash | 
					
						
							|  |  |  |       token.hash | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def eql?(other) | 
					
						
							| 
									
										
										
										
											2021-02-17 01:18:25 +05:30
										 |  |  |       instance_of?(other.class) && token == other.token | 
					
						
							| 
									
										
										
										
											2017-06-28 17:53:59 +02:00
										 |  |  |     end | 
					
						
							|  |  |  |     alias == eql? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-21 16:41:15 +02:00
										 |  |  |     def to_h | 
					
						
							| 
									
										
										
										
											2018-07-17 10:04:17 +01:00
										 |  |  |       { | 
					
						
							| 
									
										
										
										
											2024-11-07 15:50:03 -05:00
										 |  |  |         "token"                   => token, | 
					
						
							|  |  |  |         "full_token"              => full_name, | 
					
						
							|  |  |  |         "old_tokens"              => old_tokens, | 
					
						
							|  |  |  |         "tap"                     => tap&.name, | 
					
						
							|  |  |  |         "name"                    => name, | 
					
						
							|  |  |  |         "desc"                    => desc, | 
					
						
							|  |  |  |         "homepage"                => homepage, | 
					
						
							|  |  |  |         "url"                     => url, | 
					
						
							|  |  |  |         "url_specs"               => url_specs, | 
					
						
							|  |  |  |         "version"                 => version, | 
					
						
							|  |  |  |         "installed"               => installed_version, | 
					
						
							|  |  |  |         "installed_time"          => install_time&.to_i, | 
					
						
							|  |  |  |         "bundle_version"          => bundle_long_version, | 
					
						
							|  |  |  |         "bundle_short_version"    => bundle_short_version, | 
					
						
							|  |  |  |         "outdated"                => outdated?, | 
					
						
							|  |  |  |         "sha256"                  => sha256, | 
					
						
							|  |  |  |         "artifacts"               => artifacts_list, | 
					
						
							|  |  |  |         "caveats"                 => (caveats unless caveats.empty?), | 
					
						
							|  |  |  |         "depends_on"              => depends_on, | 
					
						
							|  |  |  |         "conflicts_with"          => conflicts_with, | 
					
						
							|  |  |  |         "container"               => container&.pairs, | 
					
						
							|  |  |  |         "auto_updates"            => auto_updates, | 
					
						
							|  |  |  |         "deprecated"              => deprecated?, | 
					
						
							|  |  |  |         "deprecation_date"        => deprecation_date, | 
					
						
							|  |  |  |         "deprecation_reason"      => deprecation_reason, | 
					
						
							|  |  |  |         "deprecation_replacement" => deprecation_replacement, | 
					
						
							|  |  |  |         "disabled"                => disabled?, | 
					
						
							|  |  |  |         "disable_date"            => disable_date, | 
					
						
							|  |  |  |         "disable_reason"          => disable_reason, | 
					
						
							|  |  |  |         "disable_replacement"     => disable_replacement, | 
					
						
							|  |  |  |         "tap_git_head"            => tap_git_head, | 
					
						
							|  |  |  |         "languages"               => languages, | 
					
						
							|  |  |  |         "ruby_source_path"        => ruby_source_path, | 
					
						
							|  |  |  |         "ruby_source_checksum"    => ruby_source_checksum, | 
					
						
							| 
									
										
										
										
											2018-07-02 09:05:49 +01:00
										 |  |  |       } | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2019-03-27 15:59:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-04 22:42:07 -08:00
										 |  |  |     def to_internal_api_hash | 
					
						
							| 
									
										
										
										
											2024-03-02 15:01:49 -08:00
										 |  |  |       api_hash = { | 
					
						
							|  |  |  |         "token"              => token, | 
					
						
							|  |  |  |         "name"               => name, | 
					
						
							|  |  |  |         "desc"               => desc, | 
					
						
							|  |  |  |         "homepage"           => homepage, | 
					
						
							|  |  |  |         "url"                => url, | 
					
						
							|  |  |  |         "version"            => version, | 
					
						
							|  |  |  |         "sha256"             => sha256, | 
					
						
							|  |  |  |         "artifacts"          => artifacts_list(compact: true), | 
					
						
							|  |  |  |         "ruby_source_path"   => ruby_source_path, | 
					
						
							|  |  |  |         "ruby_source_sha256" => ruby_source_checksum.fetch(:sha256), | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if deprecation_date | 
					
						
							|  |  |  |         api_hash["deprecation_date"] = deprecation_date | 
					
						
							|  |  |  |         api_hash["deprecation_reason"] = deprecation_reason | 
					
						
							| 
									
										
										
										
											2024-11-07 15:50:03 -05:00
										 |  |  |         api_hash["deprecation_replacement"] = deprecation_replacement | 
					
						
							| 
									
										
										
										
											2023-02-13 05:07:01 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2023-02-10 12:07:36 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-02 15:01:49 -08:00
										 |  |  |       if disable_date | 
					
						
							|  |  |  |         api_hash["disable_date"] = disable_date | 
					
						
							|  |  |  |         api_hash["disable_reason"] = disable_reason | 
					
						
							| 
									
										
										
										
											2024-11-07 15:50:03 -05:00
										 |  |  |         api_hash["disable_replacement"] = disable_replacement | 
					
						
							| 
									
										
										
										
											2024-03-02 15:01:49 -08:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (url_specs_hash = url_specs).present? | 
					
						
							|  |  |  |         api_hash["url_specs"] = url_specs_hash | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       api_hash["caskfile_only"] = true if caskfile_only? | 
					
						
							|  |  |  |       api_hash["conflicts_with"] = conflicts_with if conflicts_with.present? | 
					
						
							|  |  |  |       api_hash["depends_on"] = depends_on if depends_on.present? | 
					
						
							|  |  |  |       api_hash["container"] = container.pairs if container | 
					
						
							|  |  |  |       api_hash["caveats"] = caveats if caveats.present? | 
					
						
							|  |  |  |       api_hash["auto_updates"] = auto_updates if auto_updates | 
					
						
							|  |  |  |       api_hash["languages"] = languages if languages.present? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       api_hash | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     HASH_KEYS_TO_SKIP = %w[outdated installed versions].freeze | 
					
						
							|  |  |  |     private_constant :HASH_KEYS_TO_SKIP | 
					
						
							| 
									
										
										
										
											2022-06-23 17:19:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-02 15:01:49 -08:00
										 |  |  |     def to_hash_with_variations(hash_method: :to_h) | 
					
						
							|  |  |  |       case hash_method | 
					
						
							|  |  |  |       when :to_h | 
					
						
							|  |  |  |         if loaded_from_api? && !Homebrew::EnvConfig.no_install_from_api? | 
					
						
							|  |  |  |           return api_to_local_hash(Homebrew::API::Cask.all_casks[token].dup) | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2024-03-04 22:42:07 -08:00
										 |  |  |       when :to_internal_api_hash | 
					
						
							| 
									
										
										
										
											2024-03-02 15:01:49 -08:00
										 |  |  |         raise ArgumentError, "API Hash must be generated from Ruby source files" if loaded_from_api? | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         raise ArgumentError, "Unknown hash method #{hash_method.inspect}" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       hash = public_send(hash_method) | 
					
						
							|  |  |  |       variations = {} | 
					
						
							| 
									
										
										
										
											2022-06-23 17:19:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-13 22:35:08 +02:00
										 |  |  |       if @dsl.on_system_blocks_exist? | 
					
						
							|  |  |  |         begin | 
					
						
							|  |  |  |           MacOSVersion::SYMBOLS.keys.product(OnSystem::ARCH_OPTIONS).each do |os, arch| | 
					
						
							| 
									
										
										
										
											2024-03-07 16:20:20 +00:00
										 |  |  |             bottle_tag = ::Utils::Bottles::Tag.new(system: os, arch:) | 
					
						
							| 
									
										
										
										
											2023-05-13 22:35:08 +02:00
										 |  |  |             next unless bottle_tag.valid_combination? | 
					
						
							| 
									
										
										
										
											2024-06-20 23:19:09 -04:00
										 |  |  |             next if depends_on.macos && | 
					
						
							|  |  |  |                     !@dsl.depends_on_set_in_block? && | 
					
						
							|  |  |  |                     !depends_on.macos.allows?(bottle_tag.to_macos_version) | 
					
						
							| 
									
										
										
										
											2022-06-23 17:19:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-07 16:20:20 +00:00
										 |  |  |             Homebrew::SimulateSystem.with(os:, arch:) do | 
					
						
							| 
									
										
										
										
											2023-03-25 11:56:05 +01:00
										 |  |  |               refresh | 
					
						
							| 
									
										
										
										
											2022-06-23 17:19:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-02 15:01:49 -08:00
										 |  |  |               public_send(hash_method).each do |key, value| | 
					
						
							|  |  |  |                 next if HASH_KEYS_TO_SKIP.include? key | 
					
						
							| 
									
										
										
										
											2023-03-25 11:56:05 +01:00
										 |  |  |                 next if value.to_s == hash[key].to_s | 
					
						
							| 
									
										
										
										
											2022-06-23 17:19:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-25 11:56:05 +01:00
										 |  |  |                 variations[bottle_tag.to_sym] ||= {} | 
					
						
							|  |  |  |                 variations[bottle_tag.to_sym][key] = value | 
					
						
							|  |  |  |               end | 
					
						
							| 
									
										
										
										
											2022-06-23 17:19:27 -04:00
										 |  |  |             end | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2023-05-13 22:35:08 +02:00
										 |  |  |         ensure | 
					
						
							|  |  |  |           refresh | 
					
						
							| 
									
										
										
										
											2022-06-23 17:19:27 -04:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-04 22:42:07 -08:00
										 |  |  |       hash["variations"] = variations if hash_method != :to_internal_api_hash || variations.present? | 
					
						
							| 
									
										
										
										
											2022-06-23 17:19:27 -04:00
										 |  |  |       hash | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-22 13:31:50 -04:00
										 |  |  |     def artifacts_list(compact: false, uninstall_only: false) | 
					
						
							|  |  |  |       artifacts.filter_map do |artifact| | 
					
						
							|  |  |  |         case artifact | 
					
						
							|  |  |  |         when Artifact::AbstractFlightBlock | 
					
						
							| 
									
										
										
										
											2024-07-09 13:16:07 -04:00
										 |  |  |           uninstall_flight_block = artifact.directives.key?(:uninstall_preflight) || | 
					
						
							|  |  |  |                                    artifact.directives.key?(:uninstall_postflight) | 
					
						
							|  |  |  |           next if uninstall_only && !uninstall_flight_block | 
					
						
							| 
									
										
										
										
											2024-06-22 13:31:50 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |           # Only indicate whether this block is used as we don't load it from the API | 
					
						
							|  |  |  |           # We can skip this entirely once we move to internal JSON v3. | 
					
						
							| 
									
										
										
										
											2024-07-09 13:16:07 -04:00
										 |  |  |           { artifact.summarize.to_sym => nil } unless compact | 
					
						
							| 
									
										
										
										
											2024-06-22 13:31:50 -04:00
										 |  |  |         else | 
					
						
							|  |  |  |           zap_artifact = artifact.is_a?(Artifact::Zap) | 
					
						
							|  |  |  |           uninstall_artifact = artifact.respond_to?(:uninstall_phase) || artifact.respond_to?(:post_uninstall_phase) | 
					
						
							|  |  |  |           next if uninstall_only && !zap_artifact && !uninstall_artifact | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           { artifact.class.dsl_key => artifact.to_args } | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-27 15:59:38 +00:00
										 |  |  |     private | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-05 17:11:55 +00:00
										 |  |  |     sig { returns(T.nilable(Homebrew::BundleVersion)) } | 
					
						
							|  |  |  |     def bundle_version | 
					
						
							|  |  |  |       @bundle_version ||= if (bundle = artifacts.find { |a| a.is_a?(Artifact::App) }&.target) && | 
					
						
							|  |  |  |                              (plist = Pathname("#{bundle}/Contents/Info.plist")) && plist.exist? | 
					
						
							|  |  |  |         Homebrew::BundleVersion.from_info_plist(plist) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 05:07:01 +00:00
										 |  |  |     def api_to_local_hash(hash) | 
					
						
							|  |  |  |       hash["token"] = token | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |       hash["installed"] = installed_version | 
					
						
							| 
									
										
										
										
											2023-02-13 05:07:01 +00:00
										 |  |  |       hash["outdated"] = outdated? | 
					
						
							|  |  |  |       hash | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-02 15:01:49 -08:00
										 |  |  |     def url_specs | 
					
						
							|  |  |  |       url&.specs.dup.tap do |url_specs| | 
					
						
							|  |  |  |         case url_specs&.dig(:user_agent) | 
					
						
							|  |  |  |         when :default | 
					
						
							|  |  |  |           url_specs.delete(:user_agent) | 
					
						
							|  |  |  |         when Symbol | 
					
						
							|  |  |  |           url_specs[:user_agent] = ":#{url_specs[:user_agent]}" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   end | 
					
						
							|  |  |  | end |