Sha256: ada0da3e2e0635a951751b72b75b537cf6dbadb9e91a921301e04833f6d59b2f

Contents?: true

Size: 1.76 KB

Versions: 33

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

module Bridgetown
  module Utils
    module Platforms
      extend self

      # TODO: jruby is NOT supported by Bridgetown. This should probably
      # get removed.
      { 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 `bridgetown 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
        @proc_version ||=
          begin
            File.read("/proc/version")
          rescue Errno::ENOENT, Errno::EACCES
            nil
          end
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
bridgetown-core-0.19.3 lib/bridgetown-core/utils/platforms.rb
bridgetown-core-0.19.2 lib/bridgetown-core/utils/platforms.rb
bridgetown-core-0.19.1 lib/bridgetown-core/utils/platforms.rb
bridgetown-core-0.19.0 lib/bridgetown-core/utils/platforms.rb
bridgetown-core-0.18.6 lib/bridgetown-core/utils/platforms.rb
bridgetown-core-0.18.5 lib/bridgetown-core/utils/platforms.rb
bridgetown-core-0.18.4 lib/bridgetown-core/utils/platforms.rb
bridgetown-core-0.18.3 lib/bridgetown-core/utils/platforms.rb
bridgetown-core-0.18.2 lib/bridgetown-core/utils/platforms.rb
bridgetown-core-0.18.1 lib/bridgetown-core/utils/platforms.rb
bridgetown-core-0.18.0 lib/bridgetown-core/utils/platforms.rb
bridgetown-core-0.17.1 lib/bridgetown-core/utils/platforms.rb
bridgetown-core-0.17.0 lib/bridgetown-core/utils/platforms.rb
bridgetown-core-0.16.0 lib/bridgetown-core/utils/platforms.rb
bridgetown-core-0.16.0.beta2 lib/bridgetown-core/utils/platforms.rb
bridgetown-core-0.16.0.beta1 lib/bridgetown-core/utils/platforms.rb
bridgetown-core-0.15.0 lib/bridgetown-core/utils/platforms.rb
bridgetown-core-0.15.0.beta4 lib/bridgetown-core/utils/platforms.rb
bridgetown-core-0.15.0.beta3 lib/bridgetown-core/utils/platforms.rb
bridgetown-core-0.15.0.beta2 lib/bridgetown-core/utils/platforms.rb