Sha256: 6b390a41f469e2ab1e051effea4b6c8090716f92296312dbf827fe8944c1390b

Contents?: true

Size: 1.78 KB

Versions: 79

Compression:

Stored size: 1.78 KB

Contents

module Launchy::Detect
  # Detect the current host os family
  #
  # If the current host familiy cannot be detected then return
  # HostOsFamily::Unknown
  class HostOsFamily
    class NotFoundError < Launchy::Error; end
    extend ::Launchy::DescendantTracker

    class << self

      def detect( host_os = HostOs.new )
        found = find_child( :matches?, host_os )
        return found.new( host_os ) if found
        raise NotFoundError, "Unknown OS family for host os '#{host_os}'. #{Launchy.bug_report_message}"
      end

      def matches?( host_os )
        matching_regex.match( host_os.to_s )
      end

      def windows?() self == Windows; end
      def darwin?()  self == Darwin;  end
      def nix?()     self == Nix;     end
      def cygwin?()  self == Cygwin;  end
    end


    attr_reader :host_os
    def initialize( host_os = HostOs.new )
      @host_os = host_os
    end

    def windows?() self.class.windows?; end
    def darwin?()  self.class.darwin?;  end
    def nix?()     self.class.nix?;      end
    def cygwin?()  self.class.cygwin?;  end

    #---------------------------
    # All known host os families
    #---------------------------
    #
    class Windows < HostOsFamily
      def self.matching_regex
        /(mingw|mswin|windows)/i
      end
      def app_list( app ) app.windows_app_list; end
    end

    class Darwin < HostOsFamily
      def self.matching_regex
        /(darwin|mac os)/i
      end
      def app_list( app ) app.darwin_app_list; end
    end

    class Nix < HostOsFamily
      def self.matching_regex
        /(linux|bsd|aix|solaris)/i
      end
      def app_list( app ) app.nix_app_list; end
    end

    class Cygwin < HostOsFamily
      def self.matching_regex
        /cygwin/i
      end
      def app_list( app ) app.cygwin_app_list; end
    end
  end
end

Version data entries

79 entries across 65 versions & 6 rubygems

Version Path
launchy-2.5.2 lib/launchy/detect/host_os_family.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/launchy-2.5.0/lib/launchy/detect/host_os_family.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/launchy-2.5.0/lib/launchy/detect/host_os_family.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/launchy-2.5.0/lib/launchy/detect/host_os_family.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/launchy-2.5.0/lib/launchy/detect/host_os_family.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/launchy-2.5.0/lib/launchy/detect/host_os_family.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/launchy-2.5.0/lib/launchy/detect/host_os_family.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/launchy-2.5.0/lib/launchy/detect/host_os_family.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/launchy-2.5.0/lib/launchy/detect/host_os_family.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/launchy-2.5.0/lib/launchy/detect/host_os_family.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/launchy-2.5.0/lib/launchy/detect/host_os_family.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/launchy-2.5.0/lib/launchy/detect/host_os_family.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/launchy-2.5.0/lib/launchy/detect/host_os_family.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/launchy-2.5.0/lib/launchy/detect/host_os_family.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/launchy-2.5.0/lib/launchy/detect/host_os_family.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/launchy-2.5.0/lib/launchy/detect/host_os_family.rb
tdiary-5.1.5 vendor/bundle/ruby/2.7.0/gems/launchy-2.5.0/lib/launchy/detect/host_os_family.rb
tdiary-5.1.4 vendor/bundle/ruby/2.7.0/gems/launchy-2.5.0/lib/launchy/detect/host_os_family.rb
tdiary-5.1.3 vendor/bundle/ruby/2.6.0/gems/launchy-2.5.0/lib/launchy/detect/host_os_family.rb
tdiary-5.1.3 vendor/bundle/ruby/2.7.0/gems/launchy-2.5.0/lib/launchy/detect/host_os_family.rb