| 
									
										
										
										
											2024-08-15 07:59:49 -07:00
										 |  |  | # typed: strict | 
					
						
							| 
									
										
										
										
											2023-03-24 22:02:00 -07:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-18 15:33:49 -07:00
										 |  |  | module OS | 
					
						
							|  |  |  |   module Mac | 
					
						
							|  |  |  |     module Readall | 
					
						
							|  |  |  |       extend T::Helpers | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       requires_ancestor { Kernel } | 
					
						
							| 
									
										
										
										
											2024-09-13 12:22:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-18 15:33:49 -07:00
										 |  |  |       sig { params(tap: Tap, os_name: T.nilable(Symbol), arch: T.nilable(Symbol)).returns(T::Boolean) } | 
					
						
							| 
									
										
										
										
											2024-09-21 12:24:21 -07:00
										 |  |  |       def valid_casks?(tap, os_name: nil, arch: ::Hardware::CPU.type) | 
					
						
							| 
									
										
										
										
											2024-09-18 15:33:49 -07:00
										 |  |  |         return true if os_name == :linux | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         current_macos_version = if os_name.is_a?(Symbol) | 
					
						
							|  |  |  |           MacOSVersion.from_symbol(os_name) | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           MacOS.version | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         success = T.let(true, T::Boolean) | 
					
						
							|  |  |  |         tap.cask_files.each do |file| | 
					
						
							| 
									
										
										
										
											2024-12-04 22:49:14 +01:00
										 |  |  |           cask = ::Cask::CaskLoader.load(file) | 
					
						
							| 
									
										
										
										
											2024-09-18 15:33:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |           # 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) | 
					
						
							| 
									
										
										
										
											2024-09-13 12:22:52 -07:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2024-09-18 15:33:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |           raise "Missing URL" if cask.url.nil? | 
					
						
							|  |  |  |         rescue Interrupt | 
					
						
							|  |  |  |           raise | 
					
						
							| 
									
										
										
										
											2025-01-12 16:56:48 +00:00
										 |  |  |         # Handle all possible exceptions reading Casks. | 
					
						
							| 
									
										
										
										
											2024-09-18 15:33:49 -07:00
										 |  |  |         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 | 
					
						
							| 
									
										
										
										
											2024-09-13 12:22:52 -07:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2024-09-18 15:33:49 -07:00
										 |  |  |         success | 
					
						
							| 
									
										
										
										
											2023-03-24 22:02:00 -07:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							| 
									
										
										
										
											2024-09-05 19:56:32 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-18 15:33:49 -07:00
										 |  |  | Readall.singleton_class.prepend(OS::Mac::Readall) |