wichr 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/whichr.rb ADDED
@@ -0,0 +1,53 @@
1
+ module Whichr
2
+
3
+ # TODO add some name mapping rbx vs rubinius f.e.
4
+
5
+ def r_type
6
+ return :"#{engine.downcase}" unless engine.nil?
7
+ description.match(/\A([^\s]+)/)
8
+ :"#{$1.downcase}"
9
+ end
10
+
11
+ def which_r?(ruby)
12
+ r_type == ruby
13
+ end
14
+
15
+ alias_method :r?, :which_r?
16
+
17
+ def version
18
+ RUBY_VERSION
19
+ end
20
+
21
+ def description
22
+ RUBY_DESCRIPTION
23
+ end
24
+
25
+ def copyright
26
+ RUBY_COPYRIGHT
27
+ end
28
+
29
+ def patchlevel
30
+ RUBY_PATCHLEVEL
31
+ end
32
+
33
+ def platform
34
+ RUBY_PLATFORM
35
+ end
36
+
37
+ def release_date
38
+ RUBY_RELEASE_DATE
39
+ end
40
+
41
+ def revision
42
+ RUBY_REVISION
43
+ rescue
44
+ nil
45
+ end
46
+
47
+ def engine
48
+ RUBY_ENGINE
49
+ rescue
50
+ nil
51
+ end
52
+
53
+ end
data/readme.textile ADDED
@@ -0,0 +1,11 @@
1
+ h2. About
2
+
3
+ *which r* is a simple helper for checking running Ruby engine
4
+
5
+ h2. Usage
6
+
7
+ <pre>
8
+ include Whichr
9
+
10
+
11
+ </pre>
@@ -0,0 +1,5 @@
1
+ $:.unshift File.join(File.dirname(__FILE__),'..','..','lib')
2
+
3
+ require 'test/unit'
4
+ require 'mocha'
5
+ require 'whichr'
@@ -0,0 +1,30 @@
1
+ require 'test_helper'
2
+
3
+ class TestWichr < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @helper = Object.new
7
+ @helper.extend Whichr
8
+ end
9
+
10
+ def test_r_type_from_engine
11
+ @helper.stubs(:engine).returns("jruby")
12
+
13
+ assert_equal(:jruby, @helper.r_type)
14
+ end
15
+
16
+ def test_r_type_from_description
17
+ @helper.stubs(:engine).returns(nil)
18
+ @helper.stubs(:description).returns("ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin10.2.0]")
19
+
20
+ assert_equal(:ruby, @helper.r_type)
21
+ end
22
+
23
+ def test_r_type
24
+ assert_equal(:ruby, @helper.r_type)
25
+ end
26
+
27
+ def test_which_r?
28
+ assert_equal(true, @helper.which_r?(:ruby))
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wichr
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: whichr 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/whichr.rb
32
+ has_rdoc: true
33
+ homepage: http://github.com/phoet/wichr
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 whichr and use r_type or wich_r? :ruby methods
64
+ test_files:
65
+ - test/test_helper.rb
66
+ - test/test_whichr.rb