Skip to content

Commit

Permalink
Merge pull request #474 from kachick/ruby3.3
Browse files Browse the repository at this point in the history
Update to Ruby 3.3 era
  • Loading branch information
kachick authored Jan 10, 2024
2 parents c0e06da + 7976e0c commit abed77b
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 60 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ jobs:
matrix:
os: ['ubuntu-latest']
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for 'n.0'
ruby: ['head', '3.2', '3.1']
ruby: ['head', '3.3', '3.2']
# # Disabled macos runner. This gem should work because of it is written in pure ruby :). And the runner is too slow and often be stacked.
# include:
# - os: 'macos-latest'
# ruby: '3.2'
# ruby: '3.3'
# # Windows CI takes longtime. It has been succeeded in #223, it is enough for now.
# - os: 'windows-latest'
# ruby: '3.2'
# ruby: '3.3'
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand Down
7 changes: 4 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require:
- rubocop-thread_safety

AllCops:
TargetRubyVersion: 3.1
TargetRubyVersion: 3.2
DisplayCopNames: true
Exclude:
- '**/vendor/**/*'
Expand Down Expand Up @@ -650,10 +650,11 @@ Style/StringMethods:
Style/Strip:
Enabled: true

Style/StructInheritance:
Style/DataInheritance:
Enabled: true
Exclude:
- 'lib/ulid/uuid.rb'
# Using `Fields = Data.define do; end` syntax made https://github.com/kachick/ruby-ulid/issues/233 again. So use class syntax instead
- 'lib/ulid/uuid/fields.rb'

Style/SwapValues:
Enabled: false
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.2
3.3.0
1 change: 1 addition & 0 deletions .yardopts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--exclude lib/ulid/uuid/fields.rb
--fail-on-warning
--tag dynamic:"To avoid conflict with rbs(steep) annotation. See https://github.com/soutaro/steep/tree/3994d5af99c458c2799331258fbe463db3b26d9a#2-write-ruby-code"
--hide-tag dynamic
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ $ bundle exec ruby benchmark/the_added_file.rb
- Basically should be reduced. ref: [#91](kachick/ruby-ulid#91), [#236](kachick/ruby-ulid#236)
- When having some objects, they should be frozen. ref: [#126](kachick/ruby-ulid#126)

## Tasks to drop Ruby 3.1
## Tasks to drop Ruby 3.2

- grep `RUBY_VERSION` guards
- grep `3.1` and '3.2'
- grep `3.2` and `3.3`
- Update gemspec and `TargetRubyVersion` in .rubocop.yml

## Use profiler
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Instead, herein is proposed ULID:

### Install

Tested only in the last 2 Rubies. So you need Ruby 3.1 or higher.
Tested only in the last 2 Rubies. So you need Ruby 3.2 or higher.

Add this line to your `Gemfile`.

Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ multitask(simulate_ci: %i[test_all signature_all rubocop dprint])
namespace(:signature) do
desc('Validate `rbs` syntax, this should be passed')
task(:validate_rbs) do
sh('bundle exec rbs -rsecurerandom -rmonitor -I sig validate --silent')
sh('bundle exec rbs -rsecurerandom -rmonitor -I sig validate')
end

desc('Check `rbs` definition with `steep` and save alerts into ignoring list :<')
Expand All @@ -65,7 +65,7 @@ namespace(:signature) do

desc('Run YARD without docs generating for the syntax check')
task(:validate_yard) do
sh('bundle exec yard stats --fail-on-warning')
sh('bundle exec yard stats')
end
end

Expand Down
6 changes: 3 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# https://github.com/NixOS/nix/issues/730#issuecomment-162323824
bashInteractive

ruby_3_2
ruby_3_3
# Required to build psych via irb dependency
# https://github.com/kachick/irb-power_assert/issues/116
# https://github.com/ruby/irb/pull/648
Expand Down Expand Up @@ -49,10 +49,10 @@
cp -rf ./lib $out
install -t $out/bin bin/pure-console.rb
makeWrapper $out/bin/pure-console.rb $out/bin/console \
--prefix PATH : ${nixpkgs.lib.makeBinPath [ pkgs.ruby_3_2 ]}
--prefix PATH : ${nixpkgs.lib.makeBinPath [ pkgs.ruby_3_3 ]}
'';
runtimeDependencies = [
pkgs.ruby_3_2
pkgs.ruby_3_3
pkgs.libyaml
];
};
Expand Down
31 changes: 1 addition & 30 deletions lib/ulid/uuid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

require_relative('errors')
require_relative('utils')
require_relative('uuid/fields')

class ULID
module UUID
Expand Down Expand Up @@ -37,36 +38,6 @@ def self.parse_v4_to_int(uuid)

parse_any_to_int(encoded)
end

# @see https://www.rfc-editor.org/rfc/rfc4122#section-4.1.2
# @todo Replace to Data class after dropped Ruby 3.1
# @note Using `Fields = Struct.new` syntax made https://github.com/kachick/ruby-ulid/issues/233 again. So use class syntax instead
class Fields < Struct.new(:time_low, :time_mid, :time_hi_and_version, :clock_seq_hi_and_res, :clk_seq_low, :node, keyword_init: true)
def self.raw_from_octets(octets)
case octets.pack('C*').unpack('NnnnnN')
in [Integer => time_low, Integer => time_mid, Integer => time_hi_and_version, Integer => clock_seq_hi_and_res, Integer => clk_seq_low, Integer => node]
new(time_low:, time_mid:, time_hi_and_version:, clock_seq_hi_and_res:, clk_seq_low:, node:).freeze
end
end

def self.forced_v4_from_octets(octets)
case octets.pack('C*').unpack('NnnnnN')
in [Integer => time_low, Integer => time_mid, Integer => time_hi_and_version, Integer => clock_seq_hi_and_res, Integer => clk_seq_low, Integer => node]
new(
time_low:,
time_mid:,
time_hi_and_version: (time_hi_and_version & 0x0fff) | 0x4000,
clock_seq_hi_and_res: (clock_seq_hi_and_res & 0x3fff) | 0x8000,
clk_seq_low:,
node:
).freeze
end
end

def to_s
'%08x-%04x-%04x-%04x-%04x%08x' % values
end
end
end

Ractor.make_shareable(UUID)
Expand Down
41 changes: 41 additions & 0 deletions lib/ulid/uuid/fields.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# coding: us-ascii
# frozen_string_literal: true
# shareable_constant_value: literal

# Copyright (C) 2021 Kenichi Kamiya

class ULID
module UUID
# @see https://www.rfc-editor.org/rfc/rfc4122#section-4.1.2
# @note
# - Using `Fields = Data.define do; end` syntax made https://github.com/kachick/ruby-ulid/issues/233 again. So use class syntax instead
# - This file is extracted to avoid YARD warnings "Ruby::ClassHandler: Undocumentable superclass" https://github.com/lsegal/yard/issues/737
# Partially avoiding is hard in YARD, so extracting the code and using exclude filter in yardopts...
class Fields < Data.define(:time_low, :time_mid, :time_hi_and_version, :clock_seq_hi_and_res, :clk_seq_low, :node)
def self.raw_from_octets(octets)
case octets.pack('C*').unpack('NnnnnN')
in [Integer => time_low, Integer => time_mid, Integer => time_hi_and_version, Integer => clock_seq_hi_and_res, Integer => clk_seq_low, Integer => node]
new(time_low:, time_mid:, time_hi_and_version:, clock_seq_hi_and_res:, clk_seq_low:, node:).freeze
end
end

def self.forced_v4_from_octets(octets)
case octets.pack('C*').unpack('NnnnnN')
in [Integer => time_low, Integer => time_mid, Integer => time_hi_and_version, Integer => clock_seq_hi_and_res, Integer => clk_seq_low, Integer => node]
new(
time_low:,
time_mid:,
time_hi_and_version: (time_hi_and_version & 0x0fff) | 0x4000,
clock_seq_hi_and_res: (clock_seq_hi_and_res & 0x3fff) | 0x8000,
clk_seq_low:,
node:
).freeze
end
end

def to_s
'%08x-%04x-%04x-%04x-%04x%08x' % deconstruct
end
end
end
end
2 changes: 1 addition & 1 deletion ruby-ulid.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Gem::Specification.new do |gem|
'rubygems_mfa_required' => 'true'
}

gem.required_ruby_version = Gem::Requirement.new('>= 3.1')
gem.required_ruby_version = Gem::Requirement.new('>= 3.2')

# common

Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_many_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
randomness: ulid.randomness,
octets: ulid.octets,
inspect: ulid.inspect,
uuidv4: ulid.to_uuidv4
uuidv4: ulid.to_uuidv4(force: true)
)
end
end
Expand Down
16 changes: 8 additions & 8 deletions sig/ulid.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ class ULID < Object
def self.parse_any_to_int: (String) -> Integer
def self.parse_v4_to_int: (String) -> Integer

class Fields < Struct[Integer]
attr_accessor time_low: Integer
attr_accessor time_mid: Integer
attr_accessor time_hi_and_version: Integer
attr_accessor clock_seq_hi_and_res: Integer
attr_accessor clk_seq_low: Integer
attr_accessor node: Integer
class Fields
attr_reader time_low: Integer
attr_reader time_mid: Integer
attr_reader time_hi_and_version: Integer
attr_reader clock_seq_hi_and_res: Integer
attr_reader clk_seq_low: Integer
attr_reader node: Integer
def self.raw_from_octets: (octets) -> Fields
def self.forced_v4_from_octets: (octets) -> Fields

def values: -> Array[Integer]
def deconstruct: -> Array[Integer]

private

Expand Down
2 changes: 0 additions & 2 deletions test/core/test_ulid_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,6 @@ def test_constant_regexp
assert_false(scanning_pattern.match?('80000000000000000000000000'))
assert_equal([], scanning_pattern.names)

omit_if(RUBY_VERSION < '3.2')

[subset_pattern, strict_pattern, scanning_pattern].each do |pattern|
assert_true(Regexp.linear_time?(pattern))
end
Expand Down
Binary file not shown.
Binary file not shown.
3 changes: 1 addition & 2 deletions test/many_data/fixtures/example.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# coding: utf-8
# frozen_string_literal: true

# @todo - Replace to `Data` class since dropped Ruby 3.1 - ref: https://bugs.ruby-lang.org/issues/16122
Example = Struct.new(:string, :integer, :timestamp, :randomness, :period, :to_time, :inspect, :uuidv4, :octets, keyword_init: true)
Example = Data.define(:string, :integer, :timestamp, :randomness, :period, :to_time, :inspect, :uuidv4, :octets)
2 changes: 1 addition & 1 deletion test/many_data/test_fixed_many_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# https://github.com/kachick/ruby-ulid/issues/89
class TestFixedManyData < Test::Unit::TestCase
dump_data = File.binread("#{__dir__}/fixtures/dumped_fixed_examples_2021-05-09_06-22.bin")
dump_data = File.binread("#{__dir__}/fixtures/dumped_fixed_examples_2024-01-10_07-59.bin")
EXAMPLES = Marshal.load(dump_data)

def assert_example(ulid, example)
Expand Down

0 comments on commit abed77b

Please sign in to comment.