lib/rps.rb in rps-0.0.2 vs lib/rps.rb in rps-0.0.3
- old
+ new
@@ -1,18 +1,51 @@
require "rbconfig"
+require "rps/cli"
+require "rps/runner"
+require "rps/ui"
module RPS
- def self.os
- @os ||= RbConfig::CONFIG['host_os']
+ PLATFORMS = {
+ :linux => "LinuxProcess",
+ :macosx => "MacOSXProcess"
+ }
+
+ def self.platform
+ @platform ||= (
+ host_os = RbConfig::CONFIG['host_os']
+ case host_os
+ when /mswin|msys|mingw32/
+ :windows
+ when /darwin|mac os/
+ :macosx
+ when /linux/
+ :linux
+ when /bsd/
+ :bsd
+ when /solaris/
+ :solaris
+ else
+ raise "unknown os: #{host_os.inspect}"
+ end
+ )
end
def self.check_platform
- unless os =~ /linux/i
- abort "rps only works on linux at the moment"
+ unless PLATFORMS.has_key? platform
+ abort platform_message
end
end
-end
-require "rps/cli"
-require "rps/runner"
-require "rps/process_entry"
-require "rps/ui"
\ No newline at end of file
+ def self.all
+ clazz = PLATFORMS[platform] or raise platform_message
+ const_get(clazz).all
+ end
+
+ def self.platform_message
+ "rps only works on #{SUPPORTED_PLATFORMS.inspect} at the moment"
+ end
+
+ autoload :LinuxProcess, "rps/linux_process"
+ autoload :BsdProcess, "rps/bsd_process"
+ autoload :MacOSXProcess, "rps/macosx_process"
+
+end