| 
									
										
										
										
											2025-06-16 17:33:24 +01:00
										 |  |  | # typed: strict | 
					
						
							| 
									
										
										
										
											2023-03-21 19:05:41 -07:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Used to substitute common paths with generic placeholders when generating JSON for the API. | 
					
						
							|  |  |  | module APIHashable | 
					
						
							| 
									
										
										
										
											2025-06-16 17:33:24 +01:00
										 |  |  |   sig { void } | 
					
						
							| 
									
										
										
										
											2023-03-21 19:05:41 -07:00
										 |  |  |   def generating_hash! | 
					
						
							|  |  |  |     return if generating_hash? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Apply monkeypatches for API generation | 
					
						
							| 
									
										
										
										
											2025-06-16 17:33:24 +01:00
										 |  |  |     @old_homebrew_prefix = T.let(HOMEBREW_PREFIX, T.nilable(Pathname)) | 
					
						
							|  |  |  |     @old_homebrew_cellar = T.let(HOMEBREW_CELLAR, T.nilable(Pathname)) | 
					
						
							|  |  |  |     @old_home = T.let(Dir.home, T.nilable(String)) | 
					
						
							|  |  |  |     @old_git_config_global = T.let(ENV.fetch("GIT_CONFIG_GLOBAL", nil), T.nilable(String)) | 
					
						
							| 
									
										
										
										
											2023-03-21 19:05:41 -07:00
										 |  |  |     Object.send(:remove_const, :HOMEBREW_PREFIX) | 
					
						
							|  |  |  |     Object.const_set(:HOMEBREW_PREFIX, Pathname.new(HOMEBREW_PREFIX_PLACEHOLDER)) | 
					
						
							|  |  |  |     ENV["HOME"] = HOMEBREW_HOME_PLACEHOLDER | 
					
						
							| 
									
										
										
										
											2025-06-14 01:54:12 +01:00
										 |  |  |     ENV["GIT_CONFIG_GLOBAL"] = File.join(@old_home, ".gitconfig") | 
					
						
							| 
									
										
										
										
											2023-03-21 19:05:41 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-16 17:33:24 +01:00
										 |  |  |     @generating_hash = T.let(true, T.nilable(T::Boolean)) | 
					
						
							| 
									
										
										
										
											2023-03-21 19:05:41 -07:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-16 17:33:24 +01:00
										 |  |  |   sig { void } | 
					
						
							| 
									
										
										
										
											2023-03-21 19:05:41 -07:00
										 |  |  |   def generated_hash! | 
					
						
							|  |  |  |     return unless generating_hash? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Revert monkeypatches for API generation | 
					
						
							|  |  |  |     Object.send(:remove_const, :HOMEBREW_PREFIX) | 
					
						
							|  |  |  |     Object.const_set(:HOMEBREW_PREFIX, @old_homebrew_prefix) | 
					
						
							|  |  |  |     ENV["HOME"] = @old_home | 
					
						
							| 
									
										
										
										
											2025-06-14 01:54:12 +01:00
										 |  |  |     ENV["GIT_CONFIG_GLOBAL"] = @old_git_config_global | 
					
						
							| 
									
										
										
										
											2023-03-21 19:05:41 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     @generating_hash = false | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-16 17:33:24 +01:00
										 |  |  |   sig { returns(T::Boolean) } | 
					
						
							| 
									
										
										
										
											2023-03-21 19:05:41 -07:00
										 |  |  |   def generating_hash? | 
					
						
							|  |  |  |     @generating_hash ||= false | 
					
						
							|  |  |  |     @generating_hash == true | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |