| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "options" | 
					
						
							| 
									
										
										
										
											2013-01-26 20:05:39 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 03:48:04 +02:00
										 |  |  | # Shared functions for classes which can be depended upon. | 
					
						
							| 
									
										
										
										
											2013-01-26 20:05:39 -06:00
										 |  |  | module Dependable | 
					
						
							| 
									
										
										
										
											2025-08-15 19:21:28 +01:00
										 |  |  |   extend T::Helpers | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-05 17:17:03 -05:00
										 |  |  |   # `:run` and `:linked` are no longer used but keep them here to avoid their | 
					
						
							|  |  |  |   # misuse in future. | 
					
						
							| 
									
										
										
										
											2023-06-19 06:06:15 +01:00
										 |  |  |   RESERVED_TAGS = [:build, :optional, :recommended, :run, :test, :linked, :implicit].freeze | 
					
						
							| 
									
										
										
										
											2013-01-26 20:05:39 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-22 17:03:27 -08:00
										 |  |  |   attr_reader :tags | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-15 19:21:28 +01:00
										 |  |  |   abstract! | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   sig { abstract.returns(T::Array[String]) } | 
					
						
							|  |  |  |   def option_names; end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-26 20:05:39 -06:00
										 |  |  |   def build? | 
					
						
							|  |  |  |     tags.include? :build | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def optional? | 
					
						
							|  |  |  |     tags.include? :optional | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def recommended? | 
					
						
							|  |  |  |     tags.include? :recommended | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-05 10:36:39 +00:00
										 |  |  |   def test? | 
					
						
							|  |  |  |     tags.include? :test | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-19 06:06:15 +01:00
										 |  |  |   def implicit? | 
					
						
							|  |  |  |     tags.include? :implicit | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-10 23:45:06 -05:00
										 |  |  |   def required? | 
					
						
							| 
									
										
										
										
											2018-03-05 10:36:39 +00:00
										 |  |  |     !build? && !test? && !optional? && !recommended? | 
					
						
							| 
									
										
										
										
											2013-05-10 23:45:06 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-15 10:50:38 +01:00
										 |  |  |   def option_tags | 
					
						
							|  |  |  |     tags - RESERVED_TAGS | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-26 20:05:39 -06:00
										 |  |  |   def options | 
					
						
							| 
									
										
										
										
											2015-12-15 10:50:38 +01:00
										 |  |  |     Options.create(option_tags) | 
					
						
							| 
									
										
										
										
											2013-01-26 20:05:39 -06:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2018-03-24 16:55:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def prune_from_option?(build) | 
					
						
							| 
									
										
										
										
											2023-12-14 02:52:30 +00:00
										 |  |  |     return false if !optional? && !recommended? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 16:55:16 +00:00
										 |  |  |     build.without?(self) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def prune_if_build_and_not_dependent?(dependent, formula = nil) | 
					
						
							|  |  |  |     return false unless build? | 
					
						
							|  |  |  |     return dependent.installed? unless formula | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 16:55:16 +00:00
										 |  |  |     dependent != formula | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-01-26 20:05:39 -06:00
										 |  |  | end |