Skip to content

Commit

Permalink
Add support for Ruby 3, drop support for Ruby < 2.5, remove I18nCache
Browse files Browse the repository at this point in the history
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 heartcombo#1721
Closes heartcombo#1720
  • Loading branch information
carlosantoniodasilva committed Jan 20, 2021
1 parent 19e7394 commit 0595088
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 58 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
8 changes: 3 additions & 5 deletions lib/simple_form/components/labels.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ module Labels

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
Expand Down
23 changes: 0 additions & 23 deletions lib/simple_form/i18n_cache.rb

This file was deleted.

3 changes: 0 additions & 3 deletions lib/simple_form/inputs/base.rb
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -9,8 +8,6 @@ class Base
include ERB::Util
include ActionView::Helpers::TranslationHelper

extend I18nCache

include SimpleForm::Helpers::Autofocus
include SimpleForm::Helpers::Disabled
include SimpleForm::Helpers::Readonly
Expand Down
6 changes: 2 additions & 4 deletions lib/simple_form/inputs/collection_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ class CollectionInput < Base
# 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)
Expand Down
2 changes: 1 addition & 1 deletion simple_form.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 0 additions & 4 deletions test/components/label_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

# 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)
Expand Down
4 changes: 0 additions & 4 deletions test/inputs/collection_check_boxes_input_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 0 additions & 4 deletions test/inputs/collection_radio_buttons_input_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 0 additions & 4 deletions test/inputs/collection_select_input_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 0595088

Please sign in to comment.