Skip to content

Commit

Permalink
Updated for 2.7 gem management
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeMeister committed Jan 3, 2025
1 parent 9b656f1 commit af50308
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 13 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions .irbrc
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby 3.4.1
25 changes: 25 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 14 additions & 0 deletions gemfiles/ruby-2-7/Gemfile
Original file line number Diff line number Diff line change
@@ -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'
48 changes: 48 additions & 0 deletions gemfiles/ruby-2-7/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Gemfile → gemfiles/ruby-3/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in result_vault.gemspec
gemspec
# gemspec

gem 'rake', '~> 13.0'

Expand Down
6 changes: 0 additions & 6 deletions Gemfile.lock → gemfiles/ruby-3/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
PATH
remote: .
specs:
result_vault (1.4.0)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -82,7 +77,6 @@ DEPENDENCIES
amazing_print
debug
rake (~> 13.0)
result_vault!
rspec (~> 3.0)
rubocop
simplecov
Expand Down
91 changes: 91 additions & 0 deletions ruby_version.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit af50308

Please sign in to comment.