From 8e9c98d5a81b0e070d5f7284d778912b6cca4c5d Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Sat, 7 Nov 2020 17:40:46 +0100 Subject: [PATCH 1/2] Check for `.empty?` instead of `.any?` `.any?` is not the opposite of `.empty?`, because the first one will search for truthy values inside the array and is O(n), while the latter only checks for array length and is O(1). ``` > [nil].any? => false > [nil].empty? => false ``` This change may break use cases where `config.available_locales` only contains falsy values, but that should be considered a bug in the application. Ref: https://stackoverflow.com/a/41325569 --- CHANGELOG.md | 5 +++++ lib/route_translator.rb | 6 +++--- lib/route_translator/version.rb | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 004d32e9..f784a25f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 9.0.0 / 2020-11-07 + +* [ENHANCEMENT] Check for `empty?` instead of `any?` on available_locales array +* [ENHANCEMENT] Update development dependencies + ## 8.2.1 / 2020-11-03 * [ENHANCEMENT] Fix deprecation with URI.parser ([#234](https://github.com/enriclluelles/route_translator/pull/234)) diff --git a/lib/route_translator.rb b/lib/route_translator.rb index d666d620..aafe8166 100644 --- a/lib/route_translator.rb +++ b/lib/route_translator.rb @@ -65,10 +65,10 @@ def reset_config def available_locales locales = config.available_locales - if locales.any? - locales.map(&:to_sym) - else + if locales.empty? I18n.available_locales.dup + else + locales.map(&:to_sym) end end diff --git a/lib/route_translator/version.rb b/lib/route_translator/version.rb index 49f070a0..69f401e4 100644 --- a/lib/route_translator/version.rb +++ b/lib/route_translator/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module RouteTranslator - VERSION = '8.2.1' + VERSION = '9.0.0' end From 12b1413cc9e495b80bc8a8705d63c96001ec8cbe Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Sat, 7 Nov 2020 17:42:58 +0100 Subject: [PATCH 2/2] Enable travis cache --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index ebb4b430..b322f67d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ os: linux dist: bionic language: ruby +cache: bundler rvm: - 2.4.10 - 2.5.8