ruby_version-1.0.3/ 0000755 0000041 0000041 00000000000 14515656760 014310 5 ustar www-data www-data ruby_version-1.0.3/Gemfile.lock 0000755 0000041 0000041 00000000730 14515656760 016535 0 ustar www-data www-data PATH
remote: .
specs:
ruby_version (1.0.3)
GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.4.4)
rake (13.0.6)
rspec (2.99.0)
rspec-core (~> 2.99.0)
rspec-expectations (~> 2.99.0)
rspec-mocks (~> 2.99.0)
rspec-core (2.99.2)
rspec-expectations (2.99.2)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.99.4)
PLATFORMS
ruby
DEPENDENCIES
rake (>= 12.0)
rspec (~> 2.99)
ruby_version!
BUNDLED WITH
2.2.22
ruby_version-1.0.3/.rspec 0000644 0000041 0000041 00000000040 14515656760 015417 0 ustar www-data www-data --colour --format documentation
ruby_version-1.0.3/README.md 0000644 0000041 0000041 00000002616 14515656760 015574 0 ustar www-data www-data # RubyVersion [
](https://badge.fury.io/rb/ruby_version) [
](https://github.com/janlelis/ruby_version/actions?query=workflow%3ATest)
Provides a `RubyVersion` to simplify checking for the right Ruby version in
your programs.
## Setup
On your command-line:
$ gem install ruby_version
In Ruby:
require 'ruby_version'
## Usage
# Output RUBY_VERSION
RubyVersion.to_s
# Check for the main version with a Float
RubyVersion.is? 2.1
# Use strings for exacter checking
RubyVersion.is.above '1.9.2'
RubyVersion.is.at_least '2.0.0' # or exactly, below, at_most
# You can use the common comparison operators
RubyVersion >= '1.8.7'
RubyVersion.between? '1.8.7', '1.9.2'
# Relase date checks
RubyVersion.is.older_than Date.today
RubyVersion.is.newer_than '2009-08-19'
# Misc Accessors
RubyVersion.major # => 1
RubyVersion.minor # => 8
RubyVersion.tiny # => 7
RubyVersion.patchlevel # => 249
RubyVersion.description # => "ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux]"
## Also See
- https://github.com/janlelis/ruby_engine
- https://github.com/janlelis/ruby_info
- https://github.com/rdp/os
## J-_-L
Copyright (c) 2010-2014 Jan Lelis. MIT License. Originated from the zucker gem.
ruby_version-1.0.3/spec/ 0000755 0000041 0000041 00000000000 14515656760 015242 5 ustar www-data www-data ruby_version-1.0.3/spec/ruby_version_spec.rb 0000644 0000041 0000041 00000003252 14515656760 021331 0 ustar www-data www-data require 'spec_helper'
describe 'RubyVersion' do
before :all do
@remember_version = RUBY_VERSION
capture_stderr{ RUBY_VERSION = '1.8.7' }
end
it 'should display RUBY_VERSION if called directly (to_s)' do
RubyVersion.to_s.should == '1.8.7'
end
context 'with "is" method, with parameter' do
it 'should check for main version (1.8 or 1.9) when Float paramater is given' do
RubyVersion.is?( 1.8 ).should == true
RubyVersion.is?( 1.9 ).should == false
end
it 'should check with string comparison if parameter is not Float' do
RubyVersion.is?( '1.8' ).should == false
end
end
context 'with "is" method, without parameter, but method chaining' do
it 'should return a string for usage with comparison operators' do
(RubyVersion.is > '1.8.7').should == false
(RubyVersion <= '1.8.7').should == true
(RubyVersion.is.between? '1.8.6', '1.8.7').should == true
end
it 'should create some handy compare aliases' do
RubyVersion.is.above( '1.8.7' ).should == false
RubyVersion.is.at_least( '1.8.7' ).should == true
RubyVersion.is.exactly( '1.8.7' ).should == true
end
it 'also allows to check for the release dates' do
RubyVersion.is.older_than( Date.today + 365 ).should == true
RubyVersion.is.newer_than( '2000-01-01' ).should == true
end
end
it 'should define some accessors' do
RubyVersion.major.should == 1
RubyVersion.minor.should == 8
RubyVersion.tiny.should == 7
RubyVersion.patchlevel.should == RUBY_PATCHLEVEL
RubyVersion.description.should == RUBY_DESCRIPTION
end
after :all do
capture_stderr{ RUBY_VERSION = @remember_version }
end
end
ruby_version-1.0.3/spec/spec_helper.rb 0000644 0000041 0000041 00000000503 14515656760 020056 0 ustar www-data www-data require 'ruby_version'
require 'rspec'
require 'stringio'
def capture_stdout
capture = StringIO.new
restore, $stdout = $stdout, capture
yield
$stdout = restore
capture.string
end
def capture_stderr
capture = StringIO.new
restore, $stderr = $stderr, capture
yield
$stderr = restore
capture.string
end
ruby_version-1.0.3/.gitignore 0000644 0000041 0000041 00000000021 14515656760 016271 0 ustar www-data www-data Gemfile.lock
pkg
ruby_version-1.0.3/Rakefile 0000644 0000041 0000041 00000001507 14515656760 015760 0 ustar www-data www-data # # #
# Get gemspec info
gemspec_file = Dir['*.gemspec'].first
gemspec = eval File.read(gemspec_file), binding, gemspec_file
info = "#{gemspec.name} | #{gemspec.version} | " \
"#{gemspec.runtime_dependencies.size} dependencies | " \
"#{gemspec.files.size} files"
# # #
# Gem build and install task
desc info
task :gem do
puts info + "\n\n"
print " "; sh "gem build #{gemspec_file}"
FileUtils.mkdir_p 'pkg'
FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
puts; sh %{gem install --no-document pkg/#{gemspec.name}-#{gemspec.version}.gem}
end
# # #
# Start an IRB session with the gem loaded
desc "#{gemspec.name} | IRB"
task :irb do
sh "irb -I ./lib -r #{gemspec.name.gsub '-','/'}"
end
# # #
# Spec
desc "Run specs"
task :spec do
sh "rspec"
end
task :test => :spec
task :default => :spec
ruby_version-1.0.3/lib/ 0000755 0000041 0000041 00000000000 14515656760 015056 5 ustar www-data www-data ruby_version-1.0.3/lib/ruby_version.rb 0000644 0000041 0000041 00000004242 14515656760 020133 0 ustar www-data www-data # frozen_string_literal: true
require 'date'
require 'time'
module RubyVersion
VERSION = '1.0.3'
class << self
def to_s
RUBY_VERSION
end
alias inspect to_s
# comparable
def <=>(other)
value = case other
when Integer
RUBY_VERSION.to_i
when Float
RUBY_VERSION.to_f
when String
RUBY_VERSION
when Date, Time
other.class.parse(RUBY_RELEASE_DATE)
else
other = other.to_s
RUBY_VERSION
end
value <=> other
end
include Comparable
# chaining for dsl-like language
def is?(other = nil)
if other
RubyVersion == other
else
RubyVersion
end
end
alias is is?
# aliases
alias below <
alias below? <
alias at_most <=
alias at_most? <=
alias above >
alias above? >
alias at_least >=
alias at_least? >=
alias exactly ==
alias exactly? ==
def not(other)
self != other
end
alias not? not
alias between between?
# compare dates
def newer_than(other)
if other.is_a? Date or other.is_a? Time
RubyVersion > other
else
RUBY_RELEASE_DATE > other.to_s
end
end
alias newer_than? newer_than
def older_than(other)
if other.is_a? Date or other.is_a? Time
RubyVersion < other
else
RUBY_RELEASE_DATE < other.to_s
end
end
alias older_than? older_than
def released_today
RubyVersion.date == Date.today
end
alias released_today? released_today
# accessors
def major
RUBY_VERSION.to_i
end
alias main major
def minor
RUBY_VERSION.split('.')[1].to_i
end
alias mini minor
def tiny
RUBY_VERSION.split('.')[2].to_i
end
alias teeny tiny
def patchlevel
RUBY_PATCHLEVEL
end
def platform
RUBY_PLATFORM
end
def release_date
Date.parse RUBY_RELEASE_DATE
end
alias date release_date
def description
RUBY_DESCRIPTION
end
def revision
defined?(RUBY_REVISION) && RUBY_REVISION
end
end
end
# J-_-L
ruby_version-1.0.3/ruby_version.gemspec 0000644 0000041 0000041 00000001737 14515656760 020413 0 ustar www-data www-data # -*- encoding: utf-8 -*-
require File.expand_path('../lib/ruby_version', __FILE__)
Gem::Specification.new do |gem|
gem.name = "ruby_version"
gem.version = RubyVersion::VERSION
gem.summary = 'Adds the RubyVersion pseudo-constant.'
gem.description = 'Provides a RubyVersion class which offers a convenient DSL for checking for the right Ruby version'
gem.license = "MIT"
gem.authors = ["Jan Lelis"]
gem.email = ["hi@ruby.consulting"]
gem.homepage = "https://github.com/janlelis/ruby_version"
gem.files = Dir['{**/}{.*,*}'].select { |path| File.file?(path) && path !~ /^pkg/ }
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ['lib']
gem.metadata = { "rubygems_mfa_required" => "true" }
gem.add_development_dependency 'rake', '>= 12.0'
gem.add_development_dependency 'rspec', '~> 2.99'
end
ruby_version-1.0.3/ChangeLog.md 0000644 0000041 0000041 00000000441 14515656760 016460 0 ustar www-data www-data # Change Log
## 1.0.3 / 2023-04-07
* Remove old gem versions (`pkg` dir) from release
## 1.0.2 / 2020-01-04
* Freeze string literals
## 1.0.1 / 2014-01-15
* Fix VERSION constant
* Add RubyVersion.revision method
## 1.0.0 / 2014-01-14
* Moved from zucker 13.1 gem into its own gem
ruby_version-1.0.3/Gemfile 0000644 0000041 0000041 00000000315 14515656760 015602 0 ustar www-data www-data source 'https://rubygems.org'
gemspec
### ### ###
# 3.2 workaround for RSpec 2.99, see https://bugs.ruby-lang.org/issues/17391
def File.exists?(f)exist?(f)end unless defined? File.exists?
### ### ###
ruby_version-1.0.3/LICENSE.txt 0000644 0000041 0000041 00000002035 14515656760 016133 0 ustar www-data www-data Copyright (c) 2014 Jan Lelis
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.