diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b91d5993..e7f28dfe 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 22eed88b..5e764aa0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/lib/simple_form/components/labels.rb b/lib/simple_form/components/labels.rb index bc99f1c7..9623f1e1 100644 --- a/lib/simple_form/components/labels.rb +++ b/lib/simple_form/components/labels.rb @@ -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: - %(#{translate_required_mark}) - ) - end + I18n.t(:"required.html", scope: i18n_scope, default: + %(#{translate_required_mark}) + ) end def translate_required_text diff --git a/lib/simple_form/i18n_cache.rb b/lib/simple_form/i18n_cache.rb deleted file mode 100644 index 50d69157..00000000 --- a/lib/simple_form/i18n_cache.rb +++ /dev/null @@ -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 diff --git a/lib/simple_form/inputs/base.rb b/lib/simple_form/inputs/base.rb index 67bb6ed3..1e36ec8e 100644 --- a/lib/simple_form/inputs/base.rb +++ b/lib/simple_form/inputs/base.rb @@ -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 diff --git a/lib/simple_form/inputs/collection_input.rb b/lib/simple_form/inputs/collection_input.rb index ef8c5840..6ece3a65 100644 --- a/lib/simple_form/inputs/collection_input.rb +++ b/lib/simple_form/inputs/collection_input.rb @@ -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) diff --git a/simple_form.gemspec b/simple_form.gemspec index 5e051f03..d1787961 100644 --- a/simple_form.gemspec +++ b/simple_form.gemspec @@ -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') diff --git a/test/components/label_test.rb b/test/components/label_test.rb index 0dc71742..bffaa009 100644 --- a/test/components/label_test.rb +++ b/test/components/label_test.rb @@ -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) diff --git a/test/inputs/collection_check_boxes_input_test.rb b/test/inputs/collection_check_boxes_input_test.rb index 3eaa5b93..e42fc011 100644 --- a/test/inputs/collection_check_boxes_input_test.rb +++ b/test/inputs/collection_check_boxes_input_test.rb @@ -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' diff --git a/test/inputs/collection_radio_buttons_input_test.rb b/test/inputs/collection_radio_buttons_input_test.rb index 0b660230..dd841bcd 100644 --- a/test/inputs/collection_radio_buttons_input_test.rb +++ b/test/inputs/collection_radio_buttons_input_test.rb @@ -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' diff --git a/test/inputs/collection_select_input_test.rb b/test/inputs/collection_select_input_test.rb index d5efcb27..477fa2ab 100644 --- a/test/inputs/collection_select_input_test.rb +++ b/test/inputs/collection_select_input_test.rb @@ -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'