Sha256: 862958acbd4ca3adb1d2fb7175c5595046f5c5de6a22cf7f69b997b826dcb41b

Contents?: true

Size: 1.62 KB

Versions: 13

Compression:

Stored size: 1.62 KB

Contents

module Bowline
  # Naive platform detection for Ruby
  #
  # Based on code by Matt Mower <self@mattmower.com>
  # http://matt.blogs.it/gems/ruby/platform.rb
  module Platform
    if RUBY_PLATFORM =~ /darwin/i
       OS = :unix
       IMPL = :macosx
    elsif RUBY_PLATFORM =~ /linux/i
       OS = :unix
       IMPL = :linux
    elsif RUBY_PLATFORM =~ /freebsd/i
       OS = :unix
       IMPL = :freebsd
    elsif RUBY_PLATFORM =~ /netbsd/i
       OS = :unix
       IMPL = :netbsd
    elsif RUBY_PLATFORM =~ /mswin/i
       OS = :win32
       IMPL = :mswin
    elsif RUBY_PLATFORM =~ /cygwin/i
       OS = :unix
       IMPL = :cygwin
    elsif RUBY_PLATFORM =~ /mingw/i
       OS = :win32
       IMPL = :mingw
    elsif RUBY_PLATFORM =~ /bccwin/i
       OS = :win32
       IMPL = :bccwin
    else
       OS = :unknown
       IMPL = :unknown
    end

    if RUBY_PLATFORM =~ /(i\d86)/i
       ARCH = :x86
    elsif RUBY_PLATFORM =~ /ia64/i
       ARCH = :ia64
    elsif RUBY_PLATFORM =~ /powerpc/i
       ARCH = :powerpc
    elsif RUBY_PLATFORM =~ /alpha/i
       ARCH = :alpha
    else
       ARCH = :unknown
    end
    
    def osx?
      IMPL == :macosx
    end
    module_function :osx?
    
    def linux?
      IMPL == :linux
    end
    module_function :linux?
    
    def win32?
      OS == :win32
    end
    module_function :win32?
    
    # Return OS type. An error is raised
    # on platforms unsupported by Bowline.
    # Example:
    #   Bowline::Platform.type # => :osx
    def type
      return :osx   if osx?
      return :linux if linux?
      return :win32 if win32?
      raise "Unknown platform"
    end
    module_function :type
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
bowline-0.9.4 lib/bowline/platform.rb
bowline-0.9.3 lib/bowline/platform.rb
bowline-0.9.2 lib/bowline/platform.rb
bowline-0.9.1 lib/bowline/platform.rb
bowline-0.6.3 lib/bowline/platform.rb
bowline-0.6.2 lib/bowline/platform.rb
bowline-0.6.1 lib/bowline/platform.rb
bowline-0.6.0 lib/bowline/platform.rb
bowline-0.5.8 lib/bowline/platform.rb
bowline-0.5.7 lib/bowline/platform.rb
bowline-0.5.6 lib/bowline/platform.rb
bowline-0.5.5 lib/bowline/platform.rb
bowline-0.5.4 lib/bowline/platform.rb