| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-23 14:11:05 +01:00
										 |  |  | require "hardware" | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "version" | 
					
						
							| 
									
										
										
										
											2013-02-06 22:49:43 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  | module OS | 
					
						
							|  |  |  |   module Mac | 
					
						
							|  |  |  |     class Version < ::Version | 
					
						
							|  |  |  |       SYMBOLS = { | 
					
						
							| 
									
										
										
										
											2020-07-28 16:56:55 +01:00
										 |  |  |         big_sur:     "11.0", | 
					
						
							| 
									
										
										
										
											2019-06-03 11:45:08 -07:00
										 |  |  |         catalina:    "10.15", | 
					
						
							| 
									
										
										
										
											2019-01-26 17:13:14 +00:00
										 |  |  |         mojave:      "10.14", | 
					
						
							|  |  |  |         high_sierra: "10.13", | 
					
						
							|  |  |  |         sierra:      "10.12", | 
					
						
							|  |  |  |         el_capitan:  "10.11", | 
					
						
							|  |  |  |         yosemite:    "10.10", | 
					
						
							| 
									
										
										
										
											2016-09-11 17:49:27 +01:00
										 |  |  |       }.freeze | 
					
						
							| 
									
										
										
										
											2013-06-15 19:39:27 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       def self.from_symbol(sym) | 
					
						
							| 
									
										
										
										
											2020-06-10 10:06:46 +01:00
										 |  |  |         str = SYMBOLS.fetch(sym) { raise MacOSVersionError, sym } | 
					
						
							| 
									
										
										
										
											2014-07-16 21:11:48 -05:00
										 |  |  |         new(str) | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2013-06-15 19:39:27 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-02 20:29:20 -05:00
										 |  |  |       def initialize(*args) | 
					
						
							|  |  |  |         super | 
					
						
							|  |  |  |         @comparison_cache = {} | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       def <=>(other) | 
					
						
							| 
									
										
										
										
											2014-04-02 20:29:20 -05:00
										 |  |  |         @comparison_cache.fetch(other) do | 
					
						
							| 
									
										
										
										
											2014-06-03 11:32:26 -05:00
										 |  |  |           v = SYMBOLS.fetch(other) { other.to_s } | 
					
						
							| 
									
										
										
										
											2014-04-02 20:29:20 -05:00
										 |  |  |           @comparison_cache[other] = super(Version.new(v)) | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2013-06-14 11:56:33 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       def to_sym | 
					
						
							| 
									
										
										
										
											2020-06-22 14:09:33 +01:00
										 |  |  |         SYMBOLS.invert.fetch(@version, :dunno) | 
					
						
							| 
									
										
										
										
											2013-06-14 14:47:16 -07:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2013-06-15 19:40:42 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       def pretty_name | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |         to_sym.to_s.split("_").map(&:capitalize).join(" ") | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2019-01-28 19:31:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-19 14:27:29 +10:00
										 |  |  |       # For OS::Mac::Version compatibility | 
					
						
							| 
									
										
										
										
											2019-01-28 19:31:21 +00:00
										 |  |  |       def requires_nehalem_cpu? | 
					
						
							| 
									
										
										
										
											2020-07-08 20:53:10 +02:00
										 |  |  |         unless Hardware::CPU.intel? | 
					
						
							|  |  |  |           raise "Unexpected architecture: #{Hardware::CPU.arch}. This only works with Intel architecture." | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-28 19:31:21 +00:00
										 |  |  |         Hardware.oldest_cpu(self) == :nehalem | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       # https://en.wikipedia.org/wiki/Nehalem_(microarchitecture) | 
					
						
							|  |  |  |       # Ensure any extra methods are also added to version/null.rb | 
					
						
							|  |  |  |       alias requires_sse4? requires_nehalem_cpu? | 
					
						
							|  |  |  |       alias requires_sse41? requires_nehalem_cpu? | 
					
						
							|  |  |  |       alias requires_sse42? requires_nehalem_cpu? | 
					
						
							|  |  |  |       alias requires_popcnt? requires_nehalem_cpu? | 
					
						
							| 
									
										
										
										
											2013-06-15 19:40:42 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2013-02-06 22:49:43 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | end |