Skip to content
Browse files

refactor and using a better method of os detection

  • Loading branch information...
1 parent bcfd1ac commit 3cf7aa9e87866f68befd6f6fa95f8513f5e65dcc @roja committed Jan 23, 2010
Showing with 23 additions and 35 deletions.
  1. +1 −0 README.markdown
  2. +22 −35 lib/system.rb
View
1 README.markdown
@@ -27,6 +27,7 @@ Heres a few little examples of using system within your programs.
require 'system'
HostSystem::os # => Current OS as a symbol i.e. :windows, :linux, :osx, :bsd, :darwin, :solaris
+ HostSystem::java? # => Are we running on java?
HostSystem::jruby? # => Are we running on jruby?
## Note on Patches/Pull Requests ##
View
57 lib/system.rb
@@ -1,5 +1,6 @@
# system includes
require 'singleton'
+require 'rbconfig'
# java includes
if /java/.match(RUBY_PLATFORM)
@@ -10,47 +11,33 @@
module HostSystem
def self.os
- SystemInfo.instance.os
+ return @os if defined? @os # if we already know then pass it
+ os_name = RUBY_PLATFORM
+ os_name = RbConfig::CONFIG['host_os'] if defined? RbConfig::CONFIG
+ os_name = System.getProperty('os.name').downcase if jruby?
+ @os = case os_name
+ when /linux/ then :linux
+ when /win/ then :windows
+ when /solaris/ then :solaris
+ when /bsd/ then :bsd
+ when /darwin/ then
+ defined? RbConfig::CONFIG && RbConfig::CONFIG['build_vendor'] == 'apple' ? :osx : :darwin
+ when /mac.*?os.*?x/ then :osx
+ else
+ :unknown
+ end
end
- def self.jruby?
+ def self.java?
!(/java/.match(RUBY_PLATFORM).nil?)
end
- class SystemInfo
- include Singleton
-
- def initialize
- end
-
- def os
- return @os if defined? @os # if we already know then pass it
- if HostSystem::jruby?
- @os = case System.getProperty('os.name').downcase
- when /linux/ then :linux
- when /win/ then :windows
- when /solaris/ then :solaris
- when /bsd/ then :bsd
- when /darwin/ then :darwin
- when /mac.*?os.*?x/ then :osx
- else
- :unknown
- end
- else
- potential_os = case RUBY_PLATFORM
- when /linux/ then :linux
- when /win/ then :windows
- when /solaris/ then :solaris
- when /bsd/ then :bsd
- when /darwin/ then :darwin
- else
- :unknown
- end
- potential_os = :osx if potential_os == :darwin && defined? Config::CONFIG && Config::CONFIG['build_vendor'] == 'apple'
- @os = potential_os
- end
+ def self.jruby?
+ if HostSystem::java?
+ /jruby/.match(RUBY_ENGINE)
+ else
+ false
end
-
end
end

0 comments on commit 3cf7aa9

Please sign in to comment.
Something went wrong with that request. Please try again.