| 
									
										
										
										
											2024-08-15 07:59:49 -07:00
										 |  |  | # typed: strict | 
					
						
							| 
									
										
										
										
											2023-03-24 22:02:00 -07:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-20 19:20:19 +01:00
										 |  |  | require "utils/output" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-18 15:33:49 -07:00
										 |  |  | module OS | 
					
						
							|  |  |  |   module Mac | 
					
						
							|  |  |  |     module Readall | 
					
						
							| 
									
										
										
										
											2025-06-21 21:40:57 -04:00
										 |  |  |       module ClassMethods | 
					
						
							|  |  |  |         extend T::Helpers | 
					
						
							| 
									
										
										
										
											2025-08-20 19:20:19 +01:00
										 |  |  |         include ::Utils::Output::Mixin | 
					
						
							| 
									
										
										
										
											2024-09-18 15:33:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 21:40:57 -04:00
										 |  |  |         requires_ancestor { Kernel } | 
					
						
							| 
									
										
										
										
											2024-09-13 12:22:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 21:40:57 -04:00
										 |  |  |         sig { params(tap: ::Tap, os_name: T.nilable(Symbol), arch: T.nilable(Symbol)).returns(T::Boolean) } | 
					
						
							|  |  |  |         def valid_casks?(tap, os_name: nil, arch: ::Hardware::CPU.type) | 
					
						
							|  |  |  |           return true if os_name == :linux | 
					
						
							| 
									
										
										
										
											2024-09-18 15:33:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 21:40:57 -04:00
										 |  |  |           current_macos_version = if os_name.is_a?(Symbol) | 
					
						
							|  |  |  |             MacOSVersion.from_symbol(os_name) | 
					
						
							|  |  |  |           else | 
					
						
							|  |  |  |             MacOS.version | 
					
						
							| 
									
										
										
										
											2024-09-13 12:22:52 -07:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2024-09-18 15:33:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 21:40:57 -04:00
										 |  |  |           success = T.let(true, T::Boolean) | 
					
						
							|  |  |  |           tap.cask_files.each do |file| | 
					
						
							|  |  |  |             cask = ::Cask::CaskLoader.load(file) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             # Fine to have missing URLs for unsupported macOS | 
					
						
							|  |  |  |             macos_req = cask.depends_on.macos | 
					
						
							|  |  |  |             next if macos_req&.version && Array(macos_req.version).none? do |macos_version| | 
					
						
							|  |  |  |               current_macos_version.compare(macos_req.comparator, macos_version) | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             raise "Missing URL" if cask.url.nil? | 
					
						
							|  |  |  |           rescue Interrupt | 
					
						
							|  |  |  |             raise | 
					
						
							|  |  |  |           # Handle all possible exceptions reading Casks. | 
					
						
							|  |  |  |           rescue Exception => e # rubocop:disable Lint/RescueException | 
					
						
							|  |  |  |             os_and_arch = "macOS #{current_macos_version} on #{arch}" | 
					
						
							|  |  |  |             onoe "Invalid cask (#{os_and_arch}): #{file}" | 
					
						
							|  |  |  |             $stderr.puts e | 
					
						
							|  |  |  |             success = false | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |           success | 
					
						
							| 
									
										
										
										
											2024-09-13 12:22:52 -07:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2023-03-24 22:02:00 -07:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							| 
									
										
										
										
											2024-09-05 19:56:32 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 21:40:57 -04:00
										 |  |  | Readall.singleton_class.prepend(OS::Mac::Readall::ClassMethods) |