summaryrefslogtreecommitdiff
path: root/vendor/bundle/ruby/3.4.0/gems/jekyll-4.4.1/lib/jekyll/utils/platforms.rb
blob: a6c6da902d690cec53084a7aae910861b1a97780 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# frozen_string_literal: true

module Jekyll
  module Utils
    module Platforms
      extend self

      def jruby?
        RUBY_ENGINE == "jruby"
      end

      def mri?
        RUBY_ENGINE == "ruby"
      end

      def windows?
        vanilla_windows? || bash_on_windows?
      end

      # Not a Windows Subsystem for Linux (WSL)
      def vanilla_windows?
        rbconfig_host.match?(%r!mswin|mingw|cygwin!) && proc_version.empty?
      end
      alias_method :really_windows?, :vanilla_windows?

      # Determine if Windows Subsystem for Linux (WSL)
      def bash_on_windows?
        linux_os? && microsoft_proc_version?
      end

      def linux?
        linux_os? && !microsoft_proc_version?
      end

      def osx?
        rbconfig_host.match?(%r!darwin|mac os!)
      end

      def unix?
        rbconfig_host.match?(%r!solaris|bsd!)
      end

      private

      def proc_version
        @proc_version ||= \
          begin
            File.read("/proc/version").downcase
          rescue Errno::ENOENT, Errno::EACCES
            ""
          end
      end

      def rbconfig_host
        @rbconfig_host ||= RbConfig::CONFIG["host_os"].downcase
      end

      def linux_os?
        rbconfig_host.include?("linux")
      end

      def microsoft_proc_version?
        proc_version.include?("microsoft")
      end
    end
  end
end