Sha256: 2c5c33f15c7f6033d44cf369e4cc12d88aba10adceacdcda514492ba7357f1f1

Contents?: true

Size: 1.83 KB

Versions: 247

Compression:

Stored size: 1.83 KB

Contents

module J1
  module Utils
    module Platforms
      extend self

      # Provides jruby? and mri? which respectively detect these two types of
      # tested Engines we support, in the future we might probably support the
      # other one that everyone used to talk about.

      { :jruby? => "jruby", :mri? => "ruby" }.each do |k, v|
        define_method k do
          ::RUBY_ENGINE == v
        end
      end

      # --
      # Allows you to detect "real" Windows, or what we would consider
      # "real" Windows.  That is, that we can pass the basic test and the
      # /proc/version returns nothing to us.
      # --

      def vanilla_windows?
        RbConfig::CONFIG["host_os"] =~ %r!mswin|mingw|cygwin!i && \
          !proc_version
      end

      # --
      # XXX: Remove in 4.0
      # --

      alias_method :really_windows?, \
        :vanilla_windows?

      #

      def bash_on_windows?
        RbConfig::CONFIG["host_os"] =~ %r!linux! && \
          proc_version =~ %r!microsoft!i
      end

      #

      def windows?
        vanilla_windows? || bash_on_windows?
      end

      #

      def linux?
        RbConfig::CONFIG["host_os"] =~ %r!linux! && \
          proc_version !~ %r!microsoft!i
      end

      # Provides windows?, linux?, osx?, unix? so that we can detect
      # platforms. This is mostly useful for `jekyll doctor` and for testing
      # where we kick off certain tests based on the platform.

      { :osx? => %r!darwin|mac os!, :unix? => %r!solaris|bsd! }.each do |k, v|
        define_method k do
          !!(
            RbConfig::CONFIG["host_os"] =~ v
          )
        end
      end

      #

      private
      def proc_version
        @cached_proc_version ||= begin
          Pathutil.new(
            "/proc/version"
          ).read
        rescue Errno::ENOENT
          nil
        end
      end
    end
  end
end

Version data entries

247 entries across 247 versions & 3 rubygems

Version Path
j1-template-2023.0.6 lib/j1/utils/platforms.rb
j1-template-2023.0.5 lib/j1/utils/platforms.rb
j1-template-2023.0.3 lib/j1/utils/platforms.rb
j1-template-2023.0.2 lib/j1/utils/platforms.rb
j1-template-2023.0.1 lib/j1/utils/platforms.rb
j1-template-2023.0.0 lib/j1/utils/platforms.rb
j1-template-2022.6.3 lib/j1/utils/platforms.rb
j1-template-2022.6.2 lib/j1/utils/platforms.rb
j1-template-2022.6.1 lib/j1/utils/platforms.rb
j1-template-2022.6.0 lib/j1/utils/platforms.rb
j1-template-2022.5.3 lib/j1/utils/platforms.rb
j1-template-2022.5.2 lib/j1/utils/platforms.rb
j1-template-2022.5.1 lib/j1/utils/platforms.rb
j1-template-2022.5.1.rc1 lib/j1/utils/platforms.rb
j1-template-2022.5.1.rc0 lib/j1/utils/platforms.rb
j1-template-2022.5.0 lib/j1/utils/platforms.rb
j1-template-2022.5.0.rc4 lib/j1/utils/platforms.rb
j1-template-2022.5.0.rc3 lib/j1/utils/platforms.rb
j1-template-2022.5.0.rc2 lib/j1/utils/platforms.rb
j1-template-2022.5.0.rc1 lib/j1/utils/platforms.rb