ruby_version-1.0.3/0000755000004100000410000000000014515656760014310 5ustar www-datawww-dataruby_version-1.0.3/Gemfile.lock0000755000004100000410000000073014515656760016535 0ustar www-datawww-dataPATH 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/.rspec0000644000004100000410000000004014515656760015417 0ustar www-datawww-data--colour --format documentation ruby_version-1.0.3/README.md0000644000004100000410000000261614515656760015574 0ustar www-datawww-data# RubyVersion [Gem Version](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/0000755000004100000410000000000014515656760015242 5ustar www-datawww-dataruby_version-1.0.3/spec/ruby_version_spec.rb0000644000004100000410000000325214515656760021331 0ustar www-datawww-datarequire '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.rb0000644000004100000410000000050314515656760020056 0ustar www-datawww-datarequire '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/.gitignore0000644000004100000410000000002114515656760016271 0ustar www-datawww-dataGemfile.lock pkg ruby_version-1.0.3/Rakefile0000644000004100000410000000150714515656760015760 0ustar www-datawww-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/0000755000004100000410000000000014515656760015056 5ustar www-datawww-dataruby_version-1.0.3/lib/ruby_version.rb0000644000004100000410000000424214515656760020133 0ustar www-datawww-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.gemspec0000644000004100000410000000173714515656760020413 0ustar www-datawww-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.md0000644000004100000410000000044114515656760016460 0ustar www-datawww-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/Gemfile0000644000004100000410000000031514515656760015602 0ustar www-datawww-datasource '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.txt0000644000004100000410000000203514515656760016133 0ustar www-datawww-dataCopyright (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.