which_ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/which_ruby.rb ADDED
@@ -0,0 +1,55 @@
1
+ module WhichRuby
2
+
3
+ # TODO add some name mapping rbx vs rubinius f.e.
4
+
5
+ def ruby_type
6
+ return :"#{engine.downcase}" unless engine.nil?
7
+ description.match(/\A([^\s]+)/)
8
+ :"#{$1.downcase}"
9
+ end
10
+
11
+ alias_method :rt, :ruby_type
12
+
13
+ def is_ruby_type?(type)
14
+ ruby_type == type
15
+ end
16
+
17
+ alias_method :r?, :is_ruby_type?
18
+
19
+ def version
20
+ RUBY_VERSION
21
+ end
22
+
23
+ def description
24
+ RUBY_DESCRIPTION
25
+ end
26
+
27
+ def copyright
28
+ RUBY_COPYRIGHT
29
+ end
30
+
31
+ def patchlevel
32
+ RUBY_PATCHLEVEL
33
+ end
34
+
35
+ def platform
36
+ RUBY_PLATFORM
37
+ end
38
+
39
+ def release_date
40
+ RUBY_RELEASE_DATE
41
+ end
42
+
43
+ def revision
44
+ RUBY_REVISION
45
+ rescue
46
+ nil
47
+ end
48
+
49
+ def engine
50
+ RUBY_ENGINE
51
+ rescue
52
+ nil
53
+ end
54
+
55
+ end
data/readme.textile ADDED
@@ -0,0 +1,9 @@
1
+ h2. About
2
+
3
+ *which_ruby* is a simple helper for checking running Ruby engine
4
+
5
+ h2. Usage
6
+
7
+ <pre>
8
+
9
+ </pre>
@@ -0,0 +1,5 @@
1
+ $:.unshift File.join(File.dirname(__FILE__),'..','..','lib')
2
+
3
+ require 'test/unit'
4
+ require 'mocha'
5
+ require 'which_ruby'
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+
3
+ class TestWhichRuby < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @helper = Object.new
7
+ @helper.extend WhichRuby
8
+ end
9
+
10
+ def test_r_type_from_engine
11
+ @helper.stubs(:engine).returns("jruby")
12
+
13
+ assert_equal(:jruby, @helper.ruby_type)
14
+ assert_equal(:jruby, @helper.rt)
15
+ end
16
+
17
+ def test_r_type_from_description
18
+ @helper.stubs(:engine).returns(nil)
19
+ @helper.stubs(:description).returns("ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin10.2.0]")
20
+
21
+ assert_equal(:ruby, @helper.ruby_type)
22
+ end
23
+
24
+ def test_r_type
25
+ assert_equal(:ruby, @helper.ruby_type)
26
+ end
27
+
28
+ def test_which_r?
29
+ assert_equal(true, @helper.is_ruby_type?(:ruby))
30
+ assert_equal(true, @helper.r?(:ruby))
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: which_ruby
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - "Peter Schr\xC3\xB6der"
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-25 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: which_ruby is a simple helper for checking running Ruby engine
22
+ email: phoetmail@googlemail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - readme.textile
29
+ files:
30
+ - readme.textile
31
+ - lib/which_ruby.rb
32
+ has_rdoc: true
33
+ homepage: http://github.com/phoet/which_ruby
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options:
38
+ - -a
39
+ - --inline-source
40
+ - --charset=UTF-8
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ requirements: []
58
+
59
+ rubyforge_project: none
60
+ rubygems_version: 1.3.6
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: include which_ruby module and use is_ruby_type? or ruby_type
64
+ test_files:
65
+ - test/test_helper.rb
66
+ - test/test_which_ruby.rb