ruby_version 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/.travis.yml +15 -0
- data/ChangeLog.rdoc +5 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +39 -0
- data/Rakefile +36 -0
- data/lib/ruby_version.rb +118 -0
- data/lib/ruby_version/version.rb +3 -0
- data/ruby_version.gemspec +25 -0
- data/spec/ruby_version_spec.rb +54 -0
- data/spec/spec_helper.rb +20 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 28fc2d64593515f00bd1b28cc8a90bdaa5b20115
|
4
|
+
data.tar.gz: e6d65f11d0a70c1dc7fedbf09b148ee4d228167d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d1b5b65fb773ce9fca50972e0d489d50ac2616db9c4f51f8df138970ed20ca857b1effa9405c5ba748ca1676653182b9ea81a799db981c0334b96d69515da5bd
|
7
|
+
data.tar.gz: c738f8e7936167f27f19185ef95e4cbc40411d35d3c6d0cf4190c4914f9b5b7e34579a5593a55e51ba19d317e8778dad381c6a13cfdfc85e25d4f0a64d2c18a2
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour --format documentation
|
data/.travis.yml
ADDED
data/ChangeLog.rdoc
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Jan Lelis
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
= RubyVersion {<img src="https://travis-ci.org/janlelis/ruby_version.png" />}[https://travis-ci.org/janlelis/ruby_version]
|
2
|
+
|
3
|
+
Provides a +RubyVersion+ to simplify checking for the right Ruby version in your programs.
|
4
|
+
|
5
|
+
== Setup
|
6
|
+
|
7
|
+
On your command-line:
|
8
|
+
|
9
|
+
$ gem install ruby_version
|
10
|
+
|
11
|
+
In Ruby:
|
12
|
+
|
13
|
+
require 'ruby_version'
|
14
|
+
|
15
|
+
== Usage
|
16
|
+
|
17
|
+
# return RUBY_VERSION
|
18
|
+
RubyVersion
|
19
|
+
# check for the main version with a Float
|
20
|
+
RubyVersion.is? 1.8
|
21
|
+
# use strings for exacter checking
|
22
|
+
RubyVersion.is.above '1.8.7'
|
23
|
+
RubyVersion.is.at_least '1.8.7' # or exactly, below, at_most
|
24
|
+
# you can use the common comparison operators
|
25
|
+
RubyVersion >= '1.8.7'
|
26
|
+
RubyVersion.between? '1.8.6', '1.8.7'
|
27
|
+
# relase date checks
|
28
|
+
RubyVersion.is.older_than Date.today
|
29
|
+
RubyVersion.is.newer_than '2009-08-19'
|
30
|
+
# accessors
|
31
|
+
RubyVersion.major # e.g. => 1
|
32
|
+
RubyVersion.minor # e.g. => 8
|
33
|
+
RubyVersion.tiny # e.g. => 7
|
34
|
+
RubyVersion.patchlevel # e.g. => 249
|
35
|
+
RubyVersion.description # e.g. => "ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux]"
|
36
|
+
|
37
|
+
== J-_-L
|
38
|
+
|
39
|
+
Copyright (c) 2010-2014 Jan Lelis. MIT License. Originated from the zucker gem.
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'bundler'
|
7
|
+
rescue LoadError => e
|
8
|
+
warn e.message
|
9
|
+
warn "Run `gem install bundler` to install Bundler."
|
10
|
+
exit -1
|
11
|
+
end
|
12
|
+
|
13
|
+
begin
|
14
|
+
Bundler.setup(:development)
|
15
|
+
rescue Bundler::BundlerError => e
|
16
|
+
warn e.message
|
17
|
+
warn "Run `bundle install` to install missing gems."
|
18
|
+
exit e.status_code
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake'
|
22
|
+
|
23
|
+
require 'rubygems/tasks'
|
24
|
+
Gem::Tasks.new
|
25
|
+
|
26
|
+
require 'rdoc/task'
|
27
|
+
RDoc::Task.new do |rdoc|
|
28
|
+
rdoc.title = "ruby_version"
|
29
|
+
end
|
30
|
+
task :doc => :rdoc
|
31
|
+
|
32
|
+
require 'rspec/core/rake_task'
|
33
|
+
RSpec::Core::RakeTask.new
|
34
|
+
|
35
|
+
task :test => :spec
|
36
|
+
task :default => :spec
|
data/lib/ruby_version.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'time'
|
3
|
+
|
4
|
+
module RubyVersion
|
5
|
+
class << self
|
6
|
+
def to_s
|
7
|
+
RUBY_VERSION
|
8
|
+
end
|
9
|
+
alias inspect to_s
|
10
|
+
|
11
|
+
# comparable
|
12
|
+
def <=>(other)
|
13
|
+
value = case other
|
14
|
+
when Integer
|
15
|
+
RUBY_VERSION.to_i
|
16
|
+
when Float
|
17
|
+
RUBY_VERSION.to_f
|
18
|
+
when String
|
19
|
+
RUBY_VERSION
|
20
|
+
when Date, Time
|
21
|
+
other.class.parse(RUBY_RELEASE_DATE)
|
22
|
+
else
|
23
|
+
other = other.to_s
|
24
|
+
RUBY_VERSION
|
25
|
+
end
|
26
|
+
value <=> other
|
27
|
+
end
|
28
|
+
include Comparable
|
29
|
+
|
30
|
+
# chaining for dsl-like language
|
31
|
+
def is?(other = nil)
|
32
|
+
if other
|
33
|
+
RubyVersion == other
|
34
|
+
else
|
35
|
+
RubyVersion
|
36
|
+
end
|
37
|
+
end
|
38
|
+
alias is is?
|
39
|
+
|
40
|
+
# aliases
|
41
|
+
alias below <
|
42
|
+
alias below? <
|
43
|
+
alias at_most <=
|
44
|
+
alias at_most? <=
|
45
|
+
alias above >
|
46
|
+
alias above? >
|
47
|
+
alias at_least >=
|
48
|
+
alias at_least? >=
|
49
|
+
alias exactly ==
|
50
|
+
alias exactly? ==
|
51
|
+
def not(other)
|
52
|
+
self != other
|
53
|
+
end
|
54
|
+
alias not? not
|
55
|
+
alias between between?
|
56
|
+
|
57
|
+
# compare dates
|
58
|
+
def newer_than(other)
|
59
|
+
if other.is_a? Date or other.is_a? Time
|
60
|
+
RubyVersion > other
|
61
|
+
else
|
62
|
+
RUBY_RELEASE_DATE > other.to_s
|
63
|
+
end
|
64
|
+
end
|
65
|
+
alias newer_than? newer_than
|
66
|
+
|
67
|
+
def older_than(other)
|
68
|
+
if other.is_a? Date or other.is_a? Time
|
69
|
+
RubyVersion < other
|
70
|
+
else
|
71
|
+
RUBY_RELEASE_DATE < other.to_s
|
72
|
+
end
|
73
|
+
end
|
74
|
+
alias older_than? older_than
|
75
|
+
|
76
|
+
def released_today
|
77
|
+
RubyVersion.date == Date.today
|
78
|
+
end
|
79
|
+
alias released_today? released_today
|
80
|
+
|
81
|
+
# accessors
|
82
|
+
|
83
|
+
def major
|
84
|
+
RUBY_VERSION.to_i
|
85
|
+
end
|
86
|
+
alias main major
|
87
|
+
|
88
|
+
def minor
|
89
|
+
RUBY_VERSION.split('.')[1].to_i
|
90
|
+
end
|
91
|
+
alias mini minor
|
92
|
+
|
93
|
+
def tiny
|
94
|
+
RUBY_VERSION.split('.')[2].to_i
|
95
|
+
end
|
96
|
+
|
97
|
+
alias teeny tiny
|
98
|
+
|
99
|
+
def patchlevel
|
100
|
+
RUBY_PATCHLEVEL
|
101
|
+
end
|
102
|
+
|
103
|
+
def platform
|
104
|
+
RUBY_PLATFORM
|
105
|
+
end
|
106
|
+
|
107
|
+
def release_date
|
108
|
+
Date.parse RUBY_RELEASE_DATE
|
109
|
+
end
|
110
|
+
alias date release_date
|
111
|
+
|
112
|
+
def description
|
113
|
+
RUBY_DESCRIPTION
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# J-_-L
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.expand_path('../lib/ruby_version/version', __FILE__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "ruby_version"
|
7
|
+
gem.version = RubyVersion::VERSION
|
8
|
+
gem.summary = 'Adds the RubyVersion pseudo-constant.'
|
9
|
+
gem.description = 'Provides a RubyVersion class to simplify checking for the right Ruby version in your programs.'
|
10
|
+
gem.license = "MIT"
|
11
|
+
gem.authors = ["Jan Lelis"]
|
12
|
+
gem.email = "mail@janlelis.de"
|
13
|
+
gem.homepage = "https://github.com/janlelis/ruby_version"
|
14
|
+
|
15
|
+
gem.files = Dir['{**/}{.*,*}'].select { |path| File.file?(path) }
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
|
20
|
+
gem.add_development_dependency 'bundler', '~> 1.0'
|
21
|
+
gem.add_development_dependency 'rake', '~> 10.0'
|
22
|
+
gem.add_development_dependency 'rdoc', '~> 3.0'
|
23
|
+
gem.add_development_dependency 'rspec', '~> 2.4'
|
24
|
+
gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
|
25
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'RubyVersion' do
|
4
|
+
before :all do
|
5
|
+
@remember_version = RUBY_VERSION
|
6
|
+
capture_stderr{ RUBY_VERSION = '1.8.7' }
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should display RUBY_VERSION if called directly (to_s)' do
|
10
|
+
RubyVersion.to_s.should == '1.8.7'
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'with "is" method, with parameter' do
|
14
|
+
it 'should check for main version (1.8 or 1.9) when Float paramater is given' do
|
15
|
+
RubyVersion.is?( 1.8 ).should == true
|
16
|
+
RubyVersion.is?( 1.9 ).should == false
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should check with string comparison if parameter is not Float' do
|
20
|
+
RubyVersion.is?( '1.8' ).should == false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'with "is" method, without parameter, but method chaining' do
|
25
|
+
it 'should return a string for usage with comparison operators' do
|
26
|
+
(RubyVersion.is > '1.8.7').should == false
|
27
|
+
(RubyVersion <= '1.8.7').should == true
|
28
|
+
(RubyVersion.is.between? '1.8.6', '1.8.7').should == true
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should create some handy compare aliases' do
|
32
|
+
RubyVersion.is.above( '1.8.7' ).should == false
|
33
|
+
RubyVersion.is.at_least( '1.8.7' ).should == true
|
34
|
+
RubyVersion.is.exactly( '1.8.7' ).should == true
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'also allows to check for the release dates' do
|
38
|
+
RubyVersion.is.older_than( Date.today ).should == true
|
39
|
+
RubyVersion.is.newer_than( '2000-01-01' ).should == true
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should define some accessors' do
|
44
|
+
RubyVersion.major.should == 1
|
45
|
+
RubyVersion.minor.should == 8
|
46
|
+
RubyVersion.tiny.should == 7
|
47
|
+
RubyVersion.patchlevel.should == RUBY_PATCHLEVEL
|
48
|
+
RubyVersion.description.should == RUBY_DESCRIPTION
|
49
|
+
end
|
50
|
+
|
51
|
+
after :all do
|
52
|
+
capture_stderr{ RUBY_VERSION = @remember_version }
|
53
|
+
end
|
54
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'ruby_version'
|
2
|
+
|
3
|
+
require 'rspec'
|
4
|
+
require 'stringio'
|
5
|
+
|
6
|
+
def capture_stdout
|
7
|
+
capture = StringIO.new
|
8
|
+
restore, $stdout = $stdout, capture
|
9
|
+
yield
|
10
|
+
$stdout = restore
|
11
|
+
capture.string
|
12
|
+
end
|
13
|
+
|
14
|
+
def capture_stderr
|
15
|
+
capture = StringIO.new
|
16
|
+
restore, $stderr = $stderr, capture
|
17
|
+
yield
|
18
|
+
$stderr = restore
|
19
|
+
capture.string
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby_version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jan Lelis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rdoc
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubygems-tasks
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.2'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.2'
|
83
|
+
description: Provides a RubyVersion class to simplify checking for the right Ruby
|
84
|
+
version in your programs.
|
85
|
+
email: mail@janlelis.de
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- .rspec
|
92
|
+
- .travis.yml
|
93
|
+
- ChangeLog.rdoc
|
94
|
+
- Gemfile
|
95
|
+
- Gemfile.lock
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.rdoc
|
98
|
+
- Rakefile
|
99
|
+
- lib/ruby_version.rb
|
100
|
+
- lib/ruby_version/version.rb
|
101
|
+
- ruby_version.gemspec
|
102
|
+
- spec/ruby_version_spec.rb
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
homepage: https://github.com/janlelis/ruby_version
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.2.1
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Adds the RubyVersion pseudo-constant.
|
128
|
+
test_files:
|
129
|
+
- spec/ruby_version_spec.rb
|
130
|
+
- spec/spec_helper.rb
|