Add support for Ruby 3, drop support for Ruby < 2.5, remove I18nCache
I18nCache caused some issues upgrading to Ruby 3, and at the end of the day I think it's more complexity to keep it around for a marginal gain. I18n lookups can be expensive, yes, but for most this isn't going to be a performance hit, and for those where it might be, consider looking at I18n caching alternatives that aren't specific to these few places where we had this caching, but to lookups across the board. Closes #1721 Closes #1720
This commit is contained in:
parent
19e739486c
commit
05950880ba
|
@ -10,17 +10,15 @@ jobs:
|
|||
- gemfiles/Gemfile-rails-5-2
|
||||
- gemfiles/Gemfile-rails-6-0
|
||||
ruby:
|
||||
- 2.4
|
||||
- 2.5
|
||||
- 2.6
|
||||
- 2.7
|
||||
- 3.0
|
||||
exclude:
|
||||
- ruby: 2.4
|
||||
gemfile: Gemfile
|
||||
- ruby: 2.4
|
||||
gemfile: gemfiles/Gemfile-rails-6-0
|
||||
- ruby: 2.7
|
||||
gemfile: gemfiles/Gemfile-rails-5-2
|
||||
- ruby: 3.0
|
||||
gemfile: gemfiles/Gemfile-rails-5-2
|
||||
runs-on: ubuntu-latest
|
||||
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
|
||||
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
## Unreleased
|
||||
|
||||
* Drop support for Ruby < 2.4.
|
||||
* Remove `I18nCache` module entirely. It was added complexity for very little gain in some translations, and caused extra trouble upgrading to Ruby 3. If you need that level of caching consider looking into I18n caching as a whole.
|
||||
* Add support for Ruby 3.0, drop support for Ruby < 2.5.
|
||||
* Add support for Rails 6.1, drop support for Rails < 5.2.
|
||||
* Move CI to GitHub Actions.
|
||||
|
||||
|
|
|
@ -6,11 +6,9 @@ module SimpleForm
|
|||
|
||||
module ClassMethods #:nodoc:
|
||||
def translate_required_html
|
||||
i18n_cache :translate_required_html do
|
||||
I18n.t(:"required.html", scope: i18n_scope, default:
|
||||
%(<abbr title="#{translate_required_text}">#{translate_required_mark}</abbr>)
|
||||
)
|
||||
end
|
||||
I18n.t(:"required.html", scope: i18n_scope, default:
|
||||
%(<abbr title="#{translate_required_text}">#{translate_required_mark}</abbr>)
|
||||
)
|
||||
end
|
||||
|
||||
def translate_required_text
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
module SimpleForm
|
||||
# A lot of configuration values are retrived from I18n,
|
||||
# like boolean collection, required string. This module provides
|
||||
# caching facility to speed up form construction.
|
||||
module I18nCache
|
||||
def i18n_cache(key)
|
||||
get_i18n_cache(key)[I18n.locale] ||= yield.freeze
|
||||
end
|
||||
|
||||
def get_i18n_cache(key)
|
||||
if class_variable_defined?(:"@@#{key}")
|
||||
class_variable_get(:"@@#{key}")
|
||||
else
|
||||
reset_i18n_cache(key)
|
||||
end
|
||||
end
|
||||
|
||||
def reset_i18n_cache(key)
|
||||
class_variable_set(:"@@#{key}", {})
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,5 +1,4 @@
|
|||
# frozen_string_literal: true
|
||||
require 'simple_form/i18n_cache'
|
||||
require 'active_support/core_ext/string/output_safety'
|
||||
require 'action_view/helpers'
|
||||
|
||||
|
@ -9,8 +8,6 @@ module SimpleForm
|
|||
include ERB::Util
|
||||
include ActionView::Helpers::TranslationHelper
|
||||
|
||||
extend I18nCache
|
||||
|
||||
include SimpleForm::Helpers::Autofocus
|
||||
include SimpleForm::Helpers::Disabled
|
||||
include SimpleForm::Helpers::Readonly
|
||||
|
|
|
@ -10,10 +10,8 @@ module SimpleForm
|
|||
# Texts can be translated using i18n in "simple_form.yes" and
|
||||
# "simple_form.no" keys. See the example locale file.
|
||||
def self.boolean_collection
|
||||
i18n_cache :boolean_collection do
|
||||
[ [I18n.t(:"simple_form.yes", default: 'Yes'), true],
|
||||
[I18n.t(:"simple_form.no", default: 'No'), false] ]
|
||||
end
|
||||
[ [I18n.t(:"simple_form.yes", default: 'Yes'), true],
|
||||
[I18n.t(:"simple_form.no", default: 'No'), false] ]
|
||||
end
|
||||
|
||||
def input(wrapper_options = nil)
|
||||
|
|
|
@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|||
s.test_files -= Dir["test/support/country_select/**/*"]
|
||||
s.require_paths = ["lib"]
|
||||
|
||||
s.required_ruby_version = '>= 2.4.0'
|
||||
s.required_ruby_version = '>= 2.5.0'
|
||||
|
||||
s.add_dependency('activemodel', '>= 5.2')
|
||||
s.add_dependency('actionpack', '>= 5.2')
|
||||
|
|
|
@ -4,10 +4,6 @@ require 'test_helper'
|
|||
|
||||
# Isolated tests for label without triggering f.label.
|
||||
class IsolatedLabelTest < ActionView::TestCase
|
||||
setup do
|
||||
SimpleForm::Inputs::Base.reset_i18n_cache :translate_required_html
|
||||
end
|
||||
|
||||
def with_label_for(object, attribute_name, type, options = {})
|
||||
with_concat_form_for(object) do |f|
|
||||
options[:reflection] = Association.new(Company, :company, {}) if options.delete(:setup_association)
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
require 'test_helper'
|
||||
|
||||
class CollectionCheckBoxesInputTest < ActionView::TestCase
|
||||
setup do
|
||||
SimpleForm::Inputs::CollectionCheckBoxesInput.reset_i18n_cache :boolean_collection
|
||||
end
|
||||
|
||||
test 'input check boxes does not include for attribute by default' do
|
||||
with_input_for @user, :gender, :check_boxes, collection: %i[male female]
|
||||
assert_select 'label'
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
require 'test_helper'
|
||||
|
||||
class CollectionRadioButtonsInputTest < ActionView::TestCase
|
||||
setup do
|
||||
SimpleForm::Inputs::CollectionRadioButtonsInput.reset_i18n_cache :boolean_collection
|
||||
end
|
||||
|
||||
test 'input generates boolean radio buttons by default for radio types' do
|
||||
with_input_for @user, :active, :radio_buttons
|
||||
assert_select 'input[type=radio][value=true].radio_buttons#user_active_true'
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
require 'test_helper'
|
||||
|
||||
class CollectionSelectInputTest < ActionView::TestCase
|
||||
setup do
|
||||
SimpleForm::Inputs::CollectionSelectInput.reset_i18n_cache :boolean_collection
|
||||
end
|
||||
|
||||
test 'input generates a boolean select with options by default for select types' do
|
||||
with_input_for @user, :active, :select
|
||||
assert_select 'select.select#user_active'
|
||||
|
|
Loading…
Reference in New Issue