Module: Stable::Utils::Platform
- Defined in:
- lib/stable/utils/platform.rb
Overview
Platform detection utilities for cross-platform compatibility
Class Method Summary collapse
- .current ⇒ Object
- .home_directory ⇒ Object
- .hosts_file ⇒ Object
- .linux? ⇒ Boolean
- .macos? ⇒ Boolean
- .package_manager ⇒ Object
- .unix? ⇒ Boolean
- .windows? ⇒ Boolean
Class Method Details
.current ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/stable/utils/platform.rb', line 24 def current return :macos if macos? return :linux if linux? return :windows if windows? :unknown end |
.home_directory ⇒ Object
46 47 48 49 50 |
# File 'lib/stable/utils/platform.rb', line 46 def home_directory return ENV.fetch('USERPROFILE', nil) if windows? Dir.home end |
.hosts_file ⇒ Object
39 40 41 42 43 44 |
# File 'lib/stable/utils/platform.rb', line 39 def hosts_file return '/etc/hosts' if unix? return 'C:\Windows\System32\drivers\etc\hosts' if windows? '/etc/hosts' # fallback end |
.linux? ⇒ Boolean
12 13 14 |
# File 'lib/stable/utils/platform.rb', line 12 def linux? !!(RUBY_PLATFORM =~ /linux/) end |
.macos? ⇒ Boolean
8 9 10 |
# File 'lib/stable/utils/platform.rb', line 8 def macos? !!(RUBY_PLATFORM =~ /darwin/) end |
.package_manager ⇒ Object
32 33 34 35 36 37 |
# File 'lib/stable/utils/platform.rb', line 32 def package_manager return :brew if macos? return detect_linux_package_manager if linux? :unknown end |
.unix? ⇒ Boolean
20 21 22 |
# File 'lib/stable/utils/platform.rb', line 20 def unix? !windows? end |
.windows? ⇒ Boolean
16 17 18 |
# File 'lib/stable/utils/platform.rb', line 16 def windows? !!(RUBY_PLATFORM =~ /mingw|mswin|win32/) end |