Skip to content

Commit

Permalink
Add explicit dependency to prime
Browse files Browse the repository at this point in the history
The `prime` gem has been extracted from Ruby core into a gem.

Starting with Ruby 3.4.0, it will no longer be bundled with Ruby, so it requires an explicit dependency. Ruby 3.3.0+ display a warning due to this:

```
/usr/local/bundle/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:27: warning: prime was loaded from the standard library, but is not part of the default gems since Ruby 3.1.0. Add prime to your Gemfile or
gemspec. Also contact author of fast_gettext-2.3.0 to add prime into its gemspec.
```

I also removed the fallback that uses `mathn`, as `mathn` is deprecated and not recommended to use. The `prime` gem supports Ruby 2.5.0+, same as this gem, so it should not break compatibility.
  • Loading branch information
renchap committed May 20, 2024
1 parent a4628d5 commit 6216a5c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ PATH
remote: .
specs:
fast_gettext (2.3.0)
prime

GEM
remote: https://rubygems.org/
Expand All @@ -24,6 +25,7 @@ GEM
diff-lcs (1.3)
forking_test_runner (1.3.0)
parallel_tests (>= 1.3.7)
forwardable (1.3.3)
i18n (1.2.0)
concurrent-ruby (~> 1.0)
mini_portile2 (2.8.1)
Expand All @@ -33,6 +35,9 @@ GEM
parallel
parser (3.1.0.0)
ast (~> 2.4.1)
prime (0.1.2)
forwardable
singleton
rainbow (3.1.1)
rake (12.3.2)
regexp_parser (2.2.0)
Expand Down Expand Up @@ -65,6 +70,7 @@ GEM
rubocop (>= 0.89, < 2.0)
ruby-progressbar (1.11.0)
single_cov (1.3.0)
singleton (0.2.0)
sqlite3 (1.6.0)
mini_portile2 (~> 2.8.0)
thread_safe (0.3.6)
Expand Down
1 change: 1 addition & 0 deletions fast_gettext.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Gem::Specification.new name, FastGettext::VERSION do |s|
s.files = Dir["{lib/**/*.{rb,mo,rdoc},Readme.md,CHANGELOG,LICENSE}"]
s.licenses = ["MIT", "Ruby"]
s.required_ruby_version = '>= 2.5.0'
s.add_runtime_dependency 'prime'

s.add_development_dependency 'rake'
s.add_development_dependency 'sqlite3'
Expand Down
16 changes: 3 additions & 13 deletions lib/fast_gettext/vendor/mofile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# Changes: Namespaced + uses FastGettext::Icvon

require 'stringio'
require 'prime'

module FastGettext
module GetText
Expand Down Expand Up @@ -167,19 +168,8 @@ def prime?(number)
('1' * number) !~ /^1?$|^(11+?)\1+$/
end

begin
require 'prime'
def next_prime(seed)
Prime.instance.find{|x| x > seed }
end
rescue LoadError
def next_prime(seed)
require 'mathn'
prime = Prime.new
while current = prime.succ
return current if current > seed
end
end
def next_prime(seed)
Prime.instance.find{|x| x > seed }
end

HASHWORDBITS = 32
Expand Down

0 comments on commit 6216a5c

Please sign in to comment.