Skip to content

Commit af50308

Browse files
committed
Updated for 2.7 gem management
1 parent 9b656f1 commit af50308

File tree

9 files changed

+205
-13
lines changed

9 files changed

+205
-13
lines changed

.github/workflows/build.yml

+16
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,25 @@ jobs:
2020
- "3.2"
2121
- "3.3"
2222
- "3.4"
23+
include:
24+
- ruby: "2.7"
25+
gemfile: "ruby-2-7"
26+
- ruby: "3.0"
27+
gemfile: "ruby-3"
28+
- ruby: "3.1"
29+
gemfile: "ruby-3"
30+
- ruby: "3.2"
31+
gemfile: "ruby-3"
32+
- ruby: "3.3"
33+
gemfile: "ruby-3"
34+
- ruby: "3.4"
35+
gemfile: "ruby-3"
2336

2437
runs-on: ubuntu-latest
2538

39+
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
40+
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}/Gemfile
41+
2642
steps:
2743
- uses: actions/checkout@v4
2844
- name: Set up Ruby

.irbrc

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
##
22
# Load development gems
33
#
4-
require 'debug'
4+
5+
load File.expand_path('ruby_version.rb', Dir.pwd)
6+
# require 'debug'
57

68

79
##
810
# Load all the gem files in /lib
911
#
10-
Dir['./lib/*.rb'].each { |f| load f }
11-
Dir['./lib/**/*.rb'].each { |f| load f }
12-
12+
Dir[Dir.pwd + '/lib/*.rb'].each { |f| load f }
13+
Dir[Dir.pwd + '/lib/**/*.rb'].each { |f| load f }
1314

15+
puts "LOADED"
1416
##
1517
# Reload all the gem files in /lib
1618
#
1719
def reload!
18-
Dir['./lib/*.rb'].each { |f| load f }
19-
Dir['./lib/**/*.rb'].each { |f| load f }
20+
load File.expand_path('ruby_version.rb', Dir.pwd)
21+
Dir[Dir.pwd + '/lib/*.rb'].each { |f| load f }
22+
Dir[Dir.pwd + '/lib/**/*.rb'].each { |f| load f }
2023
end

.tool-versions

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ruby 3.4.1

Rakefile

+25
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,32 @@
22

33
require "bundler/gem_tasks"
44
require "rspec/core/rake_task"
5+
require "./ruby_version"
56

67
RSpec::Core::RakeTask.new(:spec)
78

89
task default: :spec
10+
11+
12+
desc "Installs gems using the correct gemfile for the current version of ruby."
13+
task :bundle do
14+
puts "Installing from '#{RubyVersion.gemfile}'"
15+
system("bundle --gemfile=#{RubyVersion.gemfile}")
16+
system("bundle lock --add-platform x86_64-linux --gemfile=#{RubyVersion.gemfile}")
17+
end
18+
19+
20+
21+
desc "Runs bundle outdated for the current version of ruby."
22+
task :outdated do
23+
puts "Checking outdated for '#{RubyVersion.gemfile}'"
24+
system("BUNDLE_GEMFILE=#{RubyVersion.gemfile} bundle outdated")
25+
end
26+
27+
28+
29+
desc "Runs bundle update for the current version of ruby."
30+
task :update do
31+
puts "Updating for '#{RubyVersion.gemfile}'"
32+
system("BUNDLE_GEMFILE=#{RubyVersion.gemfile} bundle update")
33+
end

gemfiles/ruby-2-7/Gemfile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
source 'https://rubygems.org'
4+
5+
# Specify your gem's dependencies in result_vault.gemspec
6+
# gemspec
7+
8+
gem 'rake'
9+
10+
gem 'rspec'
11+
12+
gem 'debug'
13+
14+
gem 'amazing_print'

gemfiles/ruby-2-7/Gemfile.lock

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
amazing_print (1.6.0)
5+
date (3.4.1)
6+
debug (1.10.0)
7+
irb (~> 1.10)
8+
reline (>= 0.3.8)
9+
diff-lcs (1.5.1)
10+
io-console (0.8.0)
11+
irb (1.14.3)
12+
rdoc (>= 4.0.0)
13+
reline (>= 0.4.2)
14+
psych (5.2.2)
15+
date
16+
stringio
17+
rake (13.2.1)
18+
rdoc (6.10.0)
19+
psych (>= 4.0.0)
20+
reline (0.6.0)
21+
io-console (~> 0.5)
22+
rspec (3.13.0)
23+
rspec-core (~> 3.13.0)
24+
rspec-expectations (~> 3.13.0)
25+
rspec-mocks (~> 3.13.0)
26+
rspec-core (3.13.2)
27+
rspec-support (~> 3.13.0)
28+
rspec-expectations (3.13.3)
29+
diff-lcs (>= 1.2.0, < 2.0)
30+
rspec-support (~> 3.13.0)
31+
rspec-mocks (3.13.2)
32+
diff-lcs (>= 1.2.0, < 2.0)
33+
rspec-support (~> 3.13.0)
34+
rspec-support (3.13.2)
35+
stringio (3.1.2)
36+
37+
PLATFORMS
38+
arm64-darwin-23
39+
x86_64-linux
40+
41+
DEPENDENCIES
42+
amazing_print
43+
debug
44+
rake
45+
rspec
46+
47+
BUNDLED WITH
48+
2.4.22

Gemfile gemfiles/ruby-3/Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
source 'https://rubygems.org'
44

55
# Specify your gem's dependencies in result_vault.gemspec
6-
gemspec
6+
# gemspec
77

88
gem 'rake', '~> 13.0'
99

Gemfile.lock gemfiles/ruby-3/Gemfile.lock

-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
PATH
2-
remote: .
3-
specs:
4-
result_vault (1.4.0)
5-
61
GEM
72
remote: https://rubygems.org/
83
specs:
@@ -82,7 +77,6 @@ DEPENDENCIES
8277
amazing_print
8378
debug
8479
rake (~> 13.0)
85-
result_vault!
8680
rspec (~> 3.0)
8781
rubocop
8882
simplecov

ruby_version.rb

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
##
2+
# Methods to work with the current ruby version at the MAJOR.MINOR level
3+
#
4+
module RubyVersion
5+
class << self
6+
7+
# Returns the latest known version of Ruby
8+
def latest_version
9+
Gem::Version.new('3.4')
10+
end
11+
12+
13+
14+
# Returns true if the current verion of Ruby is as defined
15+
def latest?
16+
is?(latest_version)
17+
end
18+
19+
20+
# Returns tru if the current version of Ruby matches the expected version
21+
#
22+
# expected: anything that can be stringified with String(xxx)
23+
#
24+
def is?(expected = nil)
25+
expected = refined(expected)
26+
expected == current
27+
end
28+
29+
30+
# Return a Gem::Version of the current Ruby version twith only MJOR.MINOR segments
31+
def current
32+
@current_version ||= refined RUBY_VERSION
33+
end
34+
35+
36+
37+
def ==(other)
38+
current == refined(other)
39+
end
40+
41+
42+
43+
def >(other)
44+
current > refined(other)
45+
end
46+
47+
48+
49+
def >=(other)
50+
current >= refined(other)
51+
end
52+
53+
54+
55+
def <(other)
56+
current < refined(other)
57+
end
58+
59+
60+
61+
def <=(other)
62+
current <= refined(other)
63+
end
64+
65+
66+
67+
# Returns the string filename for the current ruby version gemfile
68+
def gemfile
69+
if current == refined("2.7")
70+
"gemfiles/ruby-#{current.to_s.gsub('.','-')}/Gemfile"
71+
else
72+
"gemfiles/ruby-3/Gemfile"
73+
end
74+
end
75+
76+
77+
# ======================================================================
78+
# = Private
79+
# ======================================================================
80+
81+
# Return a Gem::Version from the given version refined down to MAJOR.MINOR segments
82+
#
83+
# version: anything that can be stringified with String(xxx)
84+
#
85+
def refined(version)
86+
version = String(version)
87+
refined_version = Gem::Version.new(version).release.segments[0..1].join('.')
88+
Gem::Version.new(refined_version)
89+
end
90+
end
91+
end

0 commit comments

Comments
 (0)