Sha256: e7c80e7571ccc88a05a228ce8ab2adbc2c8c92fa42edc3b57b5b4da1b5a2567a

Contents?: true

Size: 887 Bytes

Versions: 1

Compression:

Stored size: 887 Bytes

Contents

# frozen_string_literal: true

require 'rbconfig'

module Stackeye
  module Tools
    class Os

      HOST_OS ||= {
        bsd: /bsd/,
        freebsd: /freebsd/,
        linux: /linux|cygwin/,
        mac: /mac|darwin/,
        solaris: /solaris|sunos/,
        windows: /mswin|win|mingw/
      }.freeze

      def initialize
        @config = RbConfig::CONFIG['host_os']
      end

      def platform
        HOST_OS.keys.detect { |name| send("#{name}?") }
      end

      HOST_OS.each do |name, regex|
        define_method("#{name}?") do
          @config =~ regex
        end
      end

      class << self
        def platform
          klass = new
          klass.platform
        end

        HOST_OS.each do |name, _regex|
          define_method("#{name}?") do
            klass = new
            klass.send("#{name}?")
          end
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stackeye-0.1.0 lib/stackeye/tools/os.rb