Skip to content

Commit

Permalink
Prefer forwarding shorthand syntax on Ruby 2.7 and later
Browse files Browse the repository at this point in the history
In rails/rails#38034 the `save` definition in `ActiveRecord::Validations`
was changed from an options hash to keyword arguments to prevent warnings
on Ruby 2.7. To prevent future changes to method signatures causing
issues use the forwarding shorthand syntax available in 2.7 and later.
  • Loading branch information
pixeltrix committed May 2, 2021
1 parent 1926f8f commit 5473a39
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 7 additions & 0 deletions lib/globalize.rb
Expand Up @@ -17,6 +17,9 @@ module Globalize
ACTIVE_RECORD_60 = Gem::Version.new('6.0.0')
ACTIVE_RECORD_61 = Gem::Version.new('6.1.0')

CURRENT_RUBY = Gem::Version.new(RUBY_VERSION)
RUBY_VERSION_27 = Gem::Version.new('2.7.0')

class << self
def locale
read_locale || I18n.locale
Expand Down Expand Up @@ -64,6 +67,10 @@ def storage
RequestStore.store
end

def ruby_27?
CURRENT_RUBY >= RUBY_VERSION_27
end

def rails_42?
::ActiveRecord.version < ACTIVE_RECORD_50
end
Expand Down
5 changes: 2 additions & 3 deletions lib/globalize/active_record/instance_methods.rb
Expand Up @@ -158,9 +158,8 @@ def globalize_fallbacks(locale)
Globalize.fallbacks(locale)
end

if Globalize.rails_61?
# Rails 6.1 and later has removed positional arguments which were never used
def save(**)
if Globalize.ruby_27?
def save(...)
result = Globalize.with_locale(translation.locale || I18n.default_locale) do
without_fallbacks do
super
Expand Down

0 comments on commit 5473a39

Please sign in to comment.