diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8b2e03a..f5a5316 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,9 +20,25 @@ jobs: - "3.2" - "3.3" - "3.4" + include: + - ruby: "2.7" + gemfile: "ruby-2-7" + - ruby: "3.0" + gemfile: "ruby-3" + - ruby: "3.1" + gemfile: "ruby-3" + - ruby: "3.2" + gemfile: "ruby-3" + - ruby: "3.3" + gemfile: "ruby-3" + - ruby: "3.4" + gemfile: "ruby-3" runs-on: ubuntu-latest + env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps + BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}/Gemfile + steps: - uses: actions/checkout@v4 - name: Set up Ruby diff --git a/.irbrc b/.irbrc index 44a097c..b53d5bd 100644 --- a/.irbrc +++ b/.irbrc @@ -1,20 +1,23 @@ ## # Load development gems # -require 'debug' + +load File.expand_path('ruby_version.rb', Dir.pwd) +# require 'debug' ## # Load all the gem files in /lib # -Dir['./lib/*.rb'].each { |f| load f } -Dir['./lib/**/*.rb'].each { |f| load f } - +Dir[Dir.pwd + '/lib/*.rb'].each { |f| load f } +Dir[Dir.pwd + '/lib/**/*.rb'].each { |f| load f } +puts "LOADED" ## # Reload all the gem files in /lib # def reload! - Dir['./lib/*.rb'].each { |f| load f } - Dir['./lib/**/*.rb'].each { |f| load f } + load File.expand_path('ruby_version.rb', Dir.pwd) + Dir[Dir.pwd + '/lib/*.rb'].each { |f| load f } + Dir[Dir.pwd + '/lib/**/*.rb'].each { |f| load f } end diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..041df9a --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +ruby 3.4.1 diff --git a/Rakefile b/Rakefile index b6ae734..b9c0f2b 100644 --- a/Rakefile +++ b/Rakefile @@ -2,7 +2,32 @@ require "bundler/gem_tasks" require "rspec/core/rake_task" +require "./ruby_version" RSpec::Core::RakeTask.new(:spec) task default: :spec + + +desc "Installs gems using the correct gemfile for the current version of ruby." +task :bundle do + puts "Installing from '#{RubyVersion.gemfile}'" + system("bundle --gemfile=#{RubyVersion.gemfile}") + system("bundle lock --add-platform x86_64-linux --gemfile=#{RubyVersion.gemfile}") +end + + + +desc "Runs bundle outdated for the current version of ruby." +task :outdated do + puts "Checking outdated for '#{RubyVersion.gemfile}'" + system("BUNDLE_GEMFILE=#{RubyVersion.gemfile} bundle outdated") +end + + + +desc "Runs bundle update for the current version of ruby." +task :update do + puts "Updating for '#{RubyVersion.gemfile}'" + system("BUNDLE_GEMFILE=#{RubyVersion.gemfile} bundle update") +end diff --git a/gemfiles/ruby-2-7/Gemfile b/gemfiles/ruby-2-7/Gemfile new file mode 100644 index 0000000..8d8795f --- /dev/null +++ b/gemfiles/ruby-2-7/Gemfile @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +source 'https://rubygems.org' + +# Specify your gem's dependencies in result_vault.gemspec +# gemspec + +gem 'rake' + +gem 'rspec' + +gem 'debug' + +gem 'amazing_print' diff --git a/gemfiles/ruby-2-7/Gemfile.lock b/gemfiles/ruby-2-7/Gemfile.lock new file mode 100644 index 0000000..a735b7a --- /dev/null +++ b/gemfiles/ruby-2-7/Gemfile.lock @@ -0,0 +1,48 @@ +GEM + remote: https://rubygems.org/ + specs: + amazing_print (1.6.0) + date (3.4.1) + debug (1.10.0) + irb (~> 1.10) + reline (>= 0.3.8) + diff-lcs (1.5.1) + io-console (0.8.0) + irb (1.14.3) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + psych (5.2.2) + date + stringio + rake (13.2.1) + rdoc (6.10.0) + psych (>= 4.0.0) + reline (0.6.0) + io-console (~> 0.5) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.2) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.3) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.2) + stringio (3.1.2) + +PLATFORMS + arm64-darwin-23 + x86_64-linux + +DEPENDENCIES + amazing_print + debug + rake + rspec + +BUNDLED WITH + 2.4.22 diff --git a/Gemfile b/gemfiles/ruby-3/Gemfile similarity index 96% rename from Gemfile rename to gemfiles/ruby-3/Gemfile index 7163830..de98c60 100644 --- a/Gemfile +++ b/gemfiles/ruby-3/Gemfile @@ -3,7 +3,7 @@ source 'https://rubygems.org' # Specify your gem's dependencies in result_vault.gemspec -gemspec +# gemspec gem 'rake', '~> 13.0' diff --git a/Gemfile.lock b/gemfiles/ruby-3/Gemfile.lock similarity index 96% rename from Gemfile.lock rename to gemfiles/ruby-3/Gemfile.lock index 2373d8d..6b15ac0 100644 --- a/Gemfile.lock +++ b/gemfiles/ruby-3/Gemfile.lock @@ -1,8 +1,3 @@ -PATH - remote: . - specs: - result_vault (1.4.0) - GEM remote: https://rubygems.org/ specs: @@ -82,7 +77,6 @@ DEPENDENCIES amazing_print debug rake (~> 13.0) - result_vault! rspec (~> 3.0) rubocop simplecov diff --git a/ruby_version.rb b/ruby_version.rb new file mode 100644 index 0000000..9baa2ad --- /dev/null +++ b/ruby_version.rb @@ -0,0 +1,91 @@ +## +# Methods to work with the current ruby version at the MAJOR.MINOR level +# +module RubyVersion + class << self + + # Returns the latest known version of Ruby + def latest_version + Gem::Version.new('3.4') + end + + + + # Returns true if the current verion of Ruby is as defined + def latest? + is?(latest_version) + end + + + # Returns tru if the current version of Ruby matches the expected version + # + # expected: anything that can be stringified with String(xxx) + # + def is?(expected = nil) + expected = refined(expected) + expected == current + end + + + # Return a Gem::Version of the current Ruby version twith only MJOR.MINOR segments + def current + @current_version ||= refined RUBY_VERSION + end + + + + def ==(other) + current == refined(other) + end + + + + def >(other) + current > refined(other) + end + + + + def >=(other) + current >= refined(other) + end + + + + def <(other) + current < refined(other) + end + + + + def <=(other) + current <= refined(other) + end + + + + # Returns the string filename for the current ruby version gemfile + def gemfile + if current == refined("2.7") + "gemfiles/ruby-#{current.to_s.gsub('.','-')}/Gemfile" + else + "gemfiles/ruby-3/Gemfile" + end + end + + + # ====================================================================== + # = Private + # ====================================================================== + + # Return a Gem::Version from the given version refined down to MAJOR.MINOR segments + # + # version: anything that can be stringified with String(xxx) + # + def refined(version) + version = String(version) + refined_version = Gem::Version.new(version).release.segments[0..1].join('.') + Gem::Version.new(refined_version) + end + end +end