Module: Fontist::Utils::System
- Defined in:
- lib/fontist/utils/system.rb
Class Method Summary collapse
- .case_sensitive_filesystem? ⇒ Boolean
- .catalog_version_for_macos ⇒ Object
- .fontconfig_installed? ⇒ Boolean
- .linux? ⇒ Boolean
- .macos? ⇒ Boolean
- .macos_version ⇒ Object
- .match?(platform) ⇒ Boolean
- .parse_macos_version(version_string) ⇒ Object
-
.parse_platform_override ⇒ Object
Parse platform override (ONLY platform tag format) Returns: { os: Symbol, framework: Integer } or { os: Symbol } or nil.
- .path_separator ⇒ Object
-
.platform_override ⇒ Object
Platform override from environment (ONLY platform tags supported).
- .platform_override? ⇒ Boolean
-
.reset_cache ⇒ Object
private
Reset cached values for testing.
- .unix? ⇒ Boolean
-
.user_os ⇒ Object
rubocop:disable Metrics/MethodLength.
- .user_os_with_version ⇒ Object
- .version_in_range?(min_version, max_version) ⇒ Boolean
- .windows? ⇒ Boolean
Class Method Details
.case_sensitive_filesystem? ⇒ Boolean
88 89 90 |
# File 'lib/fontist/utils/system.rb', line 88 def self.case_sensitive_filesystem? !%i[windows macos].include?(user_os) end |
.catalog_version_for_macos ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/fontist/utils/system.rb', line 182 def self.catalog_version_for_macos # Check for platform override first if platform_override? parsed = parse_platform_override return parsed[:framework] if parsed && parsed[:framework] end version = macos_version return nil unless version # Use MacosFrameworkMetadata as single source of truth require_relative "../macos_framework_metadata" MacosFrameworkMetadata.framework_for_macos(version) end |
.fontconfig_installed? ⇒ Boolean
117 118 119 120 121 122 123 |
# File 'lib/fontist/utils/system.rb', line 117 def self.fontconfig_installed? Helpers.silence_stream($stderr) do !!Helpers.run("fc-cache -V") end rescue Errno::ENOENT false end |
.linux? ⇒ Boolean
76 77 78 |
# File 'lib/fontist/utils/system.rb', line 76 def self.linux? user_os == :linux end |
.macos? ⇒ Boolean
72 73 74 |
# File 'lib/fontist/utils/system.rb', line 72 def self.macos? user_os == :macos end |
.macos_version ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/fontist/utils/system.rb', line 125 def self.macos_version # Check for platform override first if platform_override? parsed = parse_platform_override if parsed && parsed[:framework] require_relative "../macos_framework_metadata" return MacosFrameworkMetadata.min_macos_version(parsed[:framework]) end end return nil unless user_os == :macos @macos_version ||= begin output = Helpers.run("sw_vers -productVersion") output&.strip rescue Errno::ENOENT nil end end |
.match?(platform) ⇒ Boolean
113 114 115 |
# File 'lib/fontist/utils/system.rb', line 113 def self.match?(platform) user_os_with_version.start_with?(platform) end |
.parse_macos_version(version_string) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/fontist/utils/system.rb', line 145 def self.parse_macos_version(version_string) return nil unless version_string return nil if version_string.strip.empty? # Parse version string like "10.11.6" or "26.0.0" parts = version_string.split(".").map(&:to_i) major = parts[0] || 0 minor = parts[1] || 0 patch = parts[2] || 0 # Convert to comparable integer: major * 10000 + minor * 100 + patch # This allows: 10.11.6 = 101106, 26.0.0 = 260000 major * 10000 + minor * 100 + patch end |
.parse_platform_override ⇒ Object
Parse platform override (ONLY platform tag format) Returns: { os: Symbol, framework: Integer } or { os: Symbol } or nil
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fontist/utils/system.rb', line 15 def self.parse_platform_override override = platform_override return nil unless override # "macos-font7" => { os: :macos, framework: 7 } if match = override.match(/^(macos|linux|windows)-font(\d+)$/) return { os: match[1].to_sym, framework: match[2].to_i } end # "linux" or "windows" => { os: Symbol } if override.match?(/^(macos|linux|windows)$/) return { os: override.to_sym, framework: nil } end # Invalid format Fontist.ui.error( "Invalid FONTIST_PLATFORM_OVERRIDE: #{override}\n" \ "Supported: 'macos-font<N>', 'linux', 'windows'", ) nil end |
.path_separator ⇒ Object
84 85 86 |
# File 'lib/fontist/utils/system.rb', line 84 def self.path_separator windows? ? "\\" : "/" end |
.platform_override ⇒ Object
Platform override from environment (ONLY platform tags supported)
5 6 7 |
# File 'lib/fontist/utils/system.rb', line 5 def self.platform_override ENV["FONTIST_PLATFORM_OVERRIDE"] end |
.platform_override? ⇒ Boolean
9 10 11 |
# File 'lib/fontist/utils/system.rb', line 9 def self.platform_override? !platform_override.nil? end |
.reset_cache ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reset cached values for testing
63 64 65 66 |
# File 'lib/fontist/utils/system.rb', line 63 def self.reset_cache @user_os = nil @macos_version = nil end |
.unix? ⇒ Boolean
80 81 82 |
# File 'lib/fontist/utils/system.rb', line 80 def self.unix? user_os == :unix end |
.user_os ⇒ Object
rubocop:disable Metrics/MethodLength
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fontist/utils/system.rb', line 37 def self.user_os # rubocop:disable Metrics/MethodLength # Check for platform override first if platform_override? parsed = parse_platform_override return parsed[:os] if parsed end @user_os ||= begin host_os = RbConfig::CONFIG["host_os"] case host_os when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ :windows when /darwin|mac os/ :macos when /linux/ :linux when /solaris|bsd/ :unix else raise Fontist::Error, "unknown os: #{host_os.inspect}" end end end |
.user_os_with_version ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/fontist/utils/system.rb', line 92 def self.user_os_with_version release = if windows? # Windows doesn't have uname command # Try to extract version from RbConfig or use a placeholder begin RbConfig::CONFIG["host_os"].match(/\d+/)[0] rescue StandardError "unknown" end else # Unix-like systems (macOS, Linux, etc.) have uname command begin `uname -r`.strip rescue Errno::ENOENT "unknown" end end "#{user_os}-#{release}" end |
.version_in_range?(min_version, max_version) ⇒ Boolean
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/fontist/utils/system.rb', line 160 def self.version_in_range?(min_version, max_version) current = macos_version return true unless current # Can't determine version, allow installation current_parsed = parse_macos_version(current) return true unless current_parsed # Check minimum version if min_version min_parsed = parse_macos_version(min_version) return false if min_parsed && current_parsed < min_parsed end # Check maximum version if max_version max_parsed = parse_macos_version(max_version) return false if max_parsed && current_parsed > max_parsed end true end |
.windows? ⇒ Boolean
68 69 70 |
# File 'lib/fontist/utils/system.rb', line 68 def self.windows? user_os == :windows end |