Module: Clacky::Utils::EnvironmentDetector

Defined in:
lib/clacky/utils/environment_detector.rb

Overview

Detects the current operating system environment and desktop path.

Class Method Summary collapse

Class Method Details

.desktop_pathString?

Detect the desktop directory path for the current environment.

Returns:

  • (String, nil)

    absolute path to desktop, or nil if not found



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/clacky/utils/environment_detector.rb', line 35

def self.desktop_path
  return @desktop_path if defined?(@desktop_path)

  @desktop_path = case os_type
  when :wsl
    wsl_desktop_path
  when :macos
    macos_desktop_path
  when :linux
    linux_desktop_path
  else
    fallback_desktop_path
  end
end

.os_labelObject

Human-readable OS label for injection into session context.



24
25
26
27
28
29
30
31
# File 'lib/clacky/utils/environment_detector.rb', line 24

def self.os_label
  case os_type
  when :wsl    then "WSL/Windows"
  when :macos  then "macOS"
  when :linux  then "Linux"
  else              "Unknown"
  end
end

.os_typeSymbol

Detect OS type.

Returns:

  • (Symbol)

    :wsl, :linux, :macos, or :unknown



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/clacky/utils/environment_detector.rb', line 9

def self.os_type
  return @os_type if defined?(@os_type)

  @os_type = if wsl?
    :wsl
  elsif RUBY_PLATFORM.include?("darwin")
    :macos
  elsif RUBY_PLATFORM.include?("linux")
    :linux
  else
    :unknown
  end
end

.wsl?Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
# File 'lib/clacky/utils/environment_detector.rb', line 50

def self.wsl?
  File.exist?("/proc/version") &&
    File.read("/proc/version").downcase.include?("microsoft")
rescue
  false
end