| 
									
										
										
										
											2023-03-24 22:02:00 -07:00
										 |  |  | # typed: true | 
					
						
							|  |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module Readall | 
					
						
							|  |  |  |   class << self | 
					
						
							| 
									
										
										
										
											2024-04-01 10:05:02 -07:00
										 |  |  |     undef valid_casks? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-28 14:05:09 +01:00
										 |  |  |     def valid_casks?(tap, os_name: nil, arch: Hardware::CPU.type) | 
					
						
							| 
									
										
										
										
											2023-03-24 22:02:00 -07:00
										 |  |  |       return true if os_name == :linux | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       current_macos_version = if os_name.is_a?(Symbol) | 
					
						
							| 
									
										
										
										
											2023-05-09 02:15:28 +02:00
										 |  |  |         MacOSVersion.from_symbol(os_name) | 
					
						
							| 
									
										
										
										
											2023-03-24 22:02:00 -07:00
										 |  |  |       else | 
					
						
							|  |  |  |         MacOS.version | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       success = T.let(true, T::Boolean) | 
					
						
							| 
									
										
										
										
											2023-09-28 14:05:09 +01:00
										 |  |  |       tap.cask_files.each do |file| | 
					
						
							| 
									
										
										
										
											2023-03-24 22:02:00 -07:00
										 |  |  |         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| | 
					
						
							| 
									
										
										
										
											2023-04-04 17:59:36 -07:00
										 |  |  |           current_macos_version.compare(macos_req.comparator, macos_version) | 
					
						
							| 
									
										
										
										
											2023-03-24 22:02:00 -07:00
										 |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         raise "Missing URL" if cask.url.nil? | 
					
						
							|  |  |  |       rescue Interrupt | 
					
						
							|  |  |  |         raise | 
					
						
							|  |  |  |       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 | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |