Skip to content
Browse files

Version bump to 0.1.3

  • Loading branch information...
1 parent 6684da1 commit d8e5f748353d93eee018b5975b324d6fe688029f @RyanScottLewis RyanScottLewis committed Nov 20, 2012
Showing with 242 additions and 30 deletions.
  1. +1 −1 VERSION
  2. +1 −1 lib/system.rb
  3. +3 −0 lib/system/backwards_compatibility.rb
  4. +58 −0 lib/system/os.rb
  5. +178 −27 lib/system/ruby.rb
  6. +1 −1 system.gemspec
View
2 VERSION
@@ -1 +1 @@
-0.1.2
+0.1.3
View
2 lib/system.rb
@@ -7,7 +7,7 @@
# Java includes - Have to load this way to avoid overloading of our classes
if /java/.match(RUBY_PLATFORM) # TODO: For now, this is a good place for this but it will need abstracting..
require 'java'
- import 'java.lang.System'
+ java_import java.lang.System
end
# Prepare LOAD_PATH
View
3 lib/system/backwards_compatibility.rb
@@ -9,6 +9,7 @@ class << self
#
# @return [Symbol] The name of the operating system.
# @since 0.1.0
+ # @deprecated 0.2.0
def os
System::OS.name
end
@@ -20,6 +21,7 @@ def os
#
# @return [TrueClass, FalseClass] Is the current Ruby implementation using Java?
# @since 0.1.0
+ # @deprecated 0.2.0
def java?
System::Ruby.java?
end
@@ -30,6 +32,7 @@ def java?
#
# @return [TrueClass, FalseClass] Is the current Ruby implementation JRuby?
# @since 0.1.0
+ # @deprecated 0.2.0
def jruby?
System::Ruby.jruby?
end
View
58 lib/system/os.rb
@@ -37,6 +37,64 @@ module OS
class << self
+ # @method linux?
+ # Get if the name of the operating system running on the current host is `System::OS::Linux`.
+ #
+ # @since 0.1.3
+ # @return [TrueClass, FalseClass]
+ # @example
+ # System::OS.name # => :linux
+ # System::OS.linux? # => true
+
+ # @method windows?
+ # Get if the name of the operating system running on the current host is `System::OS::Windows`.
+ #
+ # @since 0.1.3
+ # @return [TrueClass, FalseClass]
+ # @example
+ # System::OS.name # => :windows
+ # System::OS.windows? # => true
+
+ # @method solaris?
+ # Get if the name of the operating system running on the current host is `System::OS::Solaris`.
+ #
+ # @since 0.1.3
+ # @return [TrueClass, FalseClass]
+ # @example
+ # System::OS.name # => :solaris
+ # System::OS.solaris? # => true
+
+ # @method bsd?
+ # Get if the name of the operating system running on the current host is `System::OS::BSD`.
+ #
+ # @since 0.1.3
+ # @return [TrueClass, FalseClass]
+ # @example
+ # System::OS.name # => :bsd
+ # System::OS.bsd? # => true
+
+ # @method osx?
+ # Get if the name of the operating system running on the current host is `System::OS::OSX`.
+ #
+ # @since 0.1.3
+ # @return [TrueClass, FalseClass]
+ # @example
+ # System::OS.name # => :osx
+ # System::OS.osx? # => true
+
+ # @method darwin?
+ # Get if the name of the operating system running on the current host is `System::OS::Darwin`.
+ #
+ # @since 0.1.3
+ # @return [TrueClass, FalseClass]
+ # @example
+ # System::OS.name # => :darwin
+ # System::OS.darwin? # => true
+
+ [Linux, Windows, Solaris, BSD, OSX, Darwin].each do |name|
+ define_method("#{name}?") { self.name == name }
+ end
+
# Get the name of the operating system running on the current host.
#
# @return [Symbol] The name of the operating system.
View
205 lib/system/ruby.rb
@@ -1,100 +1,251 @@
require 'system'
+require 'system/os'
+require 'rubygems/platform'
class System
- # Information about the current Ruby implementation.
+ # Information about the current Ruby interpreter.
#
# @since 0.1.1
module Ruby
class << self
+ # The C language.
+ # @since 0.1.3
+ C = :c
+
+ # The C++ language.
+ # @since 0.1.3
+ CPlusPlus = :c_plus_plus
+
+ # The Java language.
+ # @since 0.1.3
+ Java = :java
+
+ # The Ruby interpreter: MRI.
+ # @since 0.1.3
+ MRI = :mri
+
+ # The Ruby interpreter: JRuby.
+ # @since 0.1.3
+ JRuby = :jruby
+
+ # The Ruby interpreter: Rubinius.
+ # @since 0.1.3
+ Rubinius = :rbx
+
+ # The Ruby interpreter: MagLev.
+ # @since 0.1.3
+ MagLev = :maglev
+
# @method copyright
- # Return the current Ruby implementation's copyright.
+ # Return the current Ruby interpreter's copyright.
#
# @since 0.1.1
- # @return [String] The current Ruby implementation's copyright.
+ # @return [String] The current Ruby interpreter's copyright.
# @example
# System::Ruby.copyright # => "ruby - Copyright (C) 1993-2012 Yukihiro Matsumoto"
+ # @method copyright?
+ # Return if we have information about the copyright.
+ #
+ # @since 0.1.3
+ # @return [TrueClass, FalseClass]
+ # @example
+ # System::Ruby.copyright # => "ruby - Copyright (C) 1993-2012 Yukihiro Matsumoto"
+ # System::Ruby.copyright? # => true
+
# @method description
- # Return the current Ruby implementation's description which includes the engine, version,
+ # Return the current Ruby interpreter's description which includes the engine, version,
# release date, revision, and platform.
#
# @since 0.1.1
- # @return [String] The current Ruby implementation's engine.
+ # @return [String] The current Ruby interpreter's engine.
# @example
- # System::Ruby.copyright # => "ruby"
+ # System::Ruby.description # => "ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]"
+
+ # @method description?
+ # Return if we have information about the description.
+ #
+ # @since 0.1.3
+ # @return [TrueClass, FalseClass]
+ # @example
+ # System::Ruby.description # => "ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]"
+ # System::Ruby.description? # => true
# @method engine
- # Return the current Ruby implementation's engine.
+ # Return the current Ruby interpreter's engine.
#
# @since 0.1.1
- # @return [String] The current Ruby implementation's engine.
+ # @return [String] The current Ruby interpreter's engine.
+ # @example
+ # System::Ruby.engine # => "ruby"
+
+ # @method engine?
+ # Return if we have information about the engine.
+ #
+ # @since 0.1.3
+ # @return [TrueClass, FalseClass]
# @example
- # System::Ruby.copyright # => "ruby"
+ # System::Ruby.engine # => "ruby"
+ # System::Ruby.engine? # => true
# @method patchlevel
- # Return the current Ruby implementation's patch-level.
+ # Return the current Ruby interpreter's patch-level.
#
# @since 0.1.1
- # @return [Integer] The current Ruby implementation's patch-level.
+ # @return [Integer] The current Ruby interpreter's patch-level.
# @example
# System::Ruby.patchlevel # => 286
+ # @method patchlevel?
+ # Return if we have information about the patchlevel.
+ #
+ # @since 0.1.3
+ # @return [TrueClass, FalseClass]
+ # @example
+ # System::Ruby.patchlevel # => 286
+ # System::Ruby.patchlevel? # => true
+
# @method platform
- # Return the system platform the current Ruby implementation is running on.
+ # Return the system platform the current Ruby interpreter is running on.
#
# @since 0.1.1
- # @return [String] The system platform the current Ruby implementation is running on.
+ # @return [String] The system platform the current Ruby interpreter is running on.
# @example
# System::Ruby.platform # => "x86_64-darwin12.2.0"
+ # @method platform?
+ # Return if we have information about the platform.
+ #
+ # @since 0.1.3
+ # @return [TrueClass, FalseClass]
+ # @example
+ # System::Ruby.platform # => "x86_64-darwin12.2.0"
+ # System::Ruby.platform? # => true
+
# @method revision
- # Return the current Ruby implementation's revision.
+ # Return the current Ruby interpreter's revision.
#
# @since 0.1.1
- # @return [Integer] The current Ruby implementation's revision.
+ # @return [Integer] The current Ruby interpreter's revision.
+ # @example
+ # System::Ruby.revision # => 37165
+
+ # @method revision?
+ # Return if we have information about the revision.
+ #
+ # @since 0.1.3
+ # @return [TrueClass, FalseClass]
# @example
# System::Ruby.revision # => 37165
+ # System::Ruby.revision? # => true
# @method release_date
- # Return the current Ruby implementation's release date.
+ # Return the current Ruby interpreter's release date.
#
# @since 0.1.1
- # @return [String] The current Ruby implementation's release date.
+ # @return [String] The current Ruby interpreter's release date.
# @example
# System::Ruby.release_date # => "2012-10-12"
+ # @method release_date?
+ # Return if we have information about the release_date.
+ #
+ # @since 0.1.3
+ # @return [TrueClass, FalseClass]
+ # @example
+ # System::Ruby.release_date # => "2012-10-12"
+ # System::Ruby.release_date? # => true
+
# @method version
- # Return the current Ruby implementation's version.
+ # Return the current Ruby interpreter's version.
#
# @since 0.1.1
- # @return [String] The current Ruby implementation's version.
+ # @return [String] The current Ruby interpreter's version.
# @example
# System::Ruby.version # => "1.9.3"
+ # @method version?
+ # Return if we have information about the version.
+ #
+ # @since 0.1.3
+ # @return [TrueClass, FalseClass]
+ # @example
+ # System::Ruby.version # => "2012-10-12"
+ # System::Ruby.version? # => true
+
Object.constants.grep(/^RUBY_/).each do |const_name|
method_name = const_name.to_s.gsub(/^RUBY_/, '').downcase.to_sym
- define_method(method_name) { Object.const_get(const_name) }
+ define_method(method_name) do
+ Object.const_defined?(const_name) ? Object.const_get(const_name) : nil
+ end
+
+ define_method("#{method_name}?") { !send(method_name).nil? }
+ end
+
+ # Return the current Ruby interpreter's name.
+ #
+ # @return [Symbol] The name of the operating system.
+ # @example Return OS name
+ # System::OS.name # => :osx
+ # @example Assert current OS
+ # System::OS.name == System::OS::OSX # => true
+ # @since 0.1.3
+ def name
+ @name ||= if !OS.windows? && ruby?
+ MRI
+ elsif ruby? && engine? && engine == 'rbx'
+ Rubinius
+ elsif ruby? && engine? && engine == 'maglev'
+ MagLev
+ elsif engine? && engine == 'jruby'
+ JRuby
+ end
end
- # Check if Ruby is using Java.
- # Delegates to System::Ruby.java? for backwards compatibility.
+ # Return the current Ruby interpreter's base language.
#
- # @return [TrueClass, FalseClass] Is the current Ruby implementation using Java?
+ # @return [Symbol] The name of the base language.
+ # @example On MRI 1.9
+ # System::Ruby.language # => :ruby
+ # @example On JRuby
+ # System::Ruby.language # => :java
+ # @since 0.1.3
+ def language
+ @language ||= if %W[rbx maglev].any? { |name| engine == name }
+ CPlusPlus
+ elsif platform =~ /java/
+ Java
+ else
+ C
+ end
+ end
+
+ # Check if Ruby is using Java as it's base language.
+ #
+ # @return [TrueClass, FalseClass]
# @since 0.1.1
def java?
- !(/java/.match(platform).nil?)
+ language == Java
+ end
+
+ # Check if Ruby is using C or CPlusPlus as it's base language.
+ #
+ # @return [TrueClass, FalseClass]
+ # @since 0.1.3
+ def ruby?
+ [C, CPlusPlus].any? { |language| self.language == language }
end
- # Check if Ruby is JRuby.
+ # Check if Ruby interpreter is JRuby.
# Delegates to System::Ruby.jruby? for backwards compatibility.
#
- # @return [TrueClass, FalseClass] Is the current Ruby implementation JRuby?
+ # @return [TrueClass, FalseClass] Is the current Ruby interpreter JRuby?
# @since 0.1.1
def jruby?
- java? ? !!(/jruby/.match(engine)) : false
+ java? ? /jruby/ =~ engine : false
end
end
View
2 system.gemspec
@@ -2,7 +2,7 @@
Gem::Specification.new do |s|
s.name = "system"
- s.version = "0.1.2"
+ s.version = "0.1.3"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Roja Buck", "Ryan Scott Lewis"]

0 comments on commit d8e5f74

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