which_ruby 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/which_ruby.rb +37 -13
- data/readme.textile +40 -2
- data/test/test_which_ruby.rb +19 -3
- metadata +12 -5
data/lib/which_ruby.rb
CHANGED
@@ -1,55 +1,79 @@
|
|
1
1
|
module WhichRuby
|
2
2
|
|
3
|
-
|
3
|
+
@@mappings = {
|
4
|
+
:rubinius => :rbx,
|
5
|
+
}
|
6
|
+
|
7
|
+
@@rubies = [:ruby, :jruby, :rbx]
|
4
8
|
|
5
9
|
def ruby_type
|
6
|
-
return :"#{
|
7
|
-
|
10
|
+
return :"#{ruby_engine.downcase}" unless ruby_engine.nil?
|
11
|
+
ruby_description.match(/\A([^\s]+)/)
|
8
12
|
:"#{$1.downcase}"
|
9
13
|
end
|
10
14
|
|
11
15
|
alias_method :rt, :ruby_type
|
12
16
|
|
13
17
|
def is_ruby_type?(type)
|
14
|
-
ruby_type == type
|
18
|
+
ruby_type == (@@mappings[type] || type)
|
15
19
|
end
|
16
20
|
|
17
21
|
alias_method :r?, :is_ruby_type?
|
18
|
-
|
19
|
-
def
|
22
|
+
|
23
|
+
def ruby_version
|
20
24
|
RUBY_VERSION
|
21
25
|
end
|
22
26
|
|
23
|
-
def
|
27
|
+
def ruby_description
|
24
28
|
RUBY_DESCRIPTION
|
25
29
|
end
|
26
30
|
|
27
|
-
def
|
31
|
+
def ruby_copyright
|
28
32
|
RUBY_COPYRIGHT
|
29
33
|
end
|
30
34
|
|
31
|
-
def
|
35
|
+
def ruby_patchlevel
|
32
36
|
RUBY_PATCHLEVEL
|
33
37
|
end
|
34
38
|
|
35
|
-
def
|
39
|
+
def ruby_platform
|
36
40
|
RUBY_PLATFORM
|
37
41
|
end
|
38
42
|
|
39
|
-
def
|
43
|
+
def ruby_release_date
|
40
44
|
RUBY_RELEASE_DATE
|
41
45
|
end
|
42
46
|
|
43
|
-
def
|
47
|
+
def ruby_revision
|
44
48
|
RUBY_REVISION
|
45
49
|
rescue
|
46
50
|
nil
|
47
51
|
end
|
48
52
|
|
49
|
-
def
|
53
|
+
def ruby_engine
|
50
54
|
RUBY_ENGINE
|
51
55
|
rescue
|
52
56
|
nil
|
53
57
|
end
|
54
58
|
|
59
|
+
def respond_to?(sym)
|
60
|
+
contains_ruby_type?(strip_sym(sym)) || super(sym)
|
61
|
+
end
|
62
|
+
|
63
|
+
def method_missing(sym, *args, &block)
|
64
|
+
name = strip_sym(sym)
|
65
|
+
return is_ruby_type?(name) if contains_ruby_type?(name)
|
66
|
+
super(sym, *args, &block)
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def strip_sym(sym)
|
72
|
+
sym.to_s.downcase[0..-2].to_sym
|
73
|
+
end
|
74
|
+
|
75
|
+
def contains_ruby_type?(name)
|
76
|
+
@@rubies.include?(@@mappings[name] || name)
|
77
|
+
end
|
78
|
+
|
55
79
|
end
|
data/readme.textile
CHANGED
@@ -1,9 +1,47 @@
|
|
1
1
|
h2. About
|
2
2
|
|
3
|
-
*which_ruby* is a simple helper for checking running Ruby
|
3
|
+
*which_ruby* is a simple helper for checking running Ruby engines.
|
4
4
|
|
5
5
|
h2. Usage
|
6
6
|
|
7
|
+
include WhichRuby in irb:
|
8
|
+
|
7
9
|
<pre>
|
10
|
+
rvm use jruby
|
11
|
+
gem install which_ruby
|
12
|
+
irb
|
13
|
+
> require 'which_ruby'
|
14
|
+
=> true
|
15
|
+
> include WhichRuby
|
16
|
+
=> Object
|
17
|
+
</pre>
|
18
|
+
|
19
|
+
access the API:
|
20
|
+
|
21
|
+
<pre>
|
22
|
+
> ruby_type
|
23
|
+
=> :jruby
|
24
|
+
> rt
|
25
|
+
=> :jruby
|
26
|
+
> is_ruby_type? :jruby
|
27
|
+
=> true
|
28
|
+
> r? :jruby
|
29
|
+
=> true
|
30
|
+
> jruby?
|
31
|
+
=> true
|
32
|
+
</pre>
|
33
|
+
|
34
|
+
h2. Examples
|
35
|
+
|
36
|
+
Run the examples with different runtimes, jruby for example:
|
37
|
+
|
38
|
+
<pre>
|
39
|
+
rvm use jruby
|
40
|
+
ruby examples/ex.rb
|
41
|
+
</pre>
|
42
|
+
|
43
|
+
h2. TODO
|
8
44
|
|
9
|
-
|
45
|
+
* improve me!
|
46
|
+
* more docs
|
47
|
+
* more todos
|
data/test/test_which_ruby.rb
CHANGED
@@ -8,15 +8,15 @@ class TestWhichRuby < Test::Unit::TestCase
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_r_type_from_engine
|
11
|
-
@helper.stubs(:
|
11
|
+
@helper.stubs(:ruby_engine).returns("jruby")
|
12
12
|
|
13
13
|
assert_equal(:jruby, @helper.ruby_type)
|
14
14
|
assert_equal(:jruby, @helper.rt)
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_r_type_from_description
|
18
|
-
@helper.stubs(:
|
19
|
-
@helper.stubs(:
|
18
|
+
@helper.stubs(:ruby_engine).returns(nil)
|
19
|
+
@helper.stubs(:ruby_description).returns("ruby 1.8.7 (2010-04-19 patchlevel 253) [i686-darwin10.4.0], MBARI 0x6770, Ruby Enterprise Edition 2010.02")
|
20
20
|
|
21
21
|
assert_equal(:ruby, @helper.ruby_type)
|
22
22
|
end
|
@@ -29,4 +29,20 @@ class TestWhichRuby < Test::Unit::TestCase
|
|
29
29
|
assert_equal(true, @helper.is_ruby_type?(:ruby))
|
30
30
|
assert_equal(true, @helper.r?(:ruby))
|
31
31
|
end
|
32
|
+
|
33
|
+
def test_which_r_with_mapping?
|
34
|
+
@helper.stubs(:ruby_engine).returns("rbx")
|
35
|
+
assert_equal(true, @helper.r?(:rubinius))
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_respond_to?
|
39
|
+
@helper.stubs(:ruby_engine).returns("jruby")
|
40
|
+
assert_equal(true, @helper.respond_to?(:jruby?))
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_jruby?
|
44
|
+
@helper.stubs(:ruby_engine).returns("jruby")
|
45
|
+
assert_equal(true, @helper.jruby?)
|
46
|
+
end
|
47
|
+
|
32
48
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: which_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- "Peter Schr\xC3\xB6der"
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-06-29 00:00:00 +02:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
@@ -29,6 +30,8 @@ extra_rdoc_files:
|
|
29
30
|
files:
|
30
31
|
- readme.textile
|
31
32
|
- lib/which_ruby.rb
|
33
|
+
- test/test_helper.rb
|
34
|
+
- test/test_which_ruby.rb
|
32
35
|
has_rdoc: true
|
33
36
|
homepage: http://github.com/phoet/which_ruby
|
34
37
|
licenses: []
|
@@ -41,26 +44,30 @@ rdoc_options:
|
|
41
44
|
require_paths:
|
42
45
|
- lib
|
43
46
|
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
44
48
|
requirements:
|
45
49
|
- - ">="
|
46
50
|
- !ruby/object:Gem::Version
|
51
|
+
hash: 3
|
47
52
|
segments:
|
48
53
|
- 0
|
49
54
|
version: "0"
|
50
55
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
51
57
|
requirements:
|
52
58
|
- - ">="
|
53
59
|
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
54
61
|
segments:
|
55
62
|
- 0
|
56
63
|
version: "0"
|
57
64
|
requirements: []
|
58
65
|
|
59
66
|
rubyforge_project: none
|
60
|
-
rubygems_version: 1.3.
|
67
|
+
rubygems_version: 1.3.7
|
61
68
|
signing_key:
|
62
69
|
specification_version: 3
|
63
|
-
summary: include which_ruby module and use is_ruby_type? or ruby_type
|
70
|
+
summary: include which_ruby module and use is_ruby_type? or ruby_type or jruby?
|
64
71
|
test_files:
|
65
72
|
- test/test_helper.rb
|
66
73
|
- test/test_which_ruby.rb
|