Skip to content

Commit

Permalink
Rename from_xxx methods with a bang !
Browse files Browse the repository at this point in the history
Per ruby conventions, as they might raise on invalid/unknown values
  • Loading branch information
AliSoftware committed Sep 16, 2021
1 parent 682acd6 commit 8204b59
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions lib/fastlane/plugin/wpmreleasetoolkit/models/locales.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def all
# @raise [RuntimeException] if at least one of the locale codes was unknown
#
%i[glotpress android google_play ios app_store].each do |key|
define_method("from_#{key}") { |args| search!(key, args) }
define_method("from_#{key}!") { |args| search!(key, args) }
end

# Return an Array<Locale> based on glotpress locale codes
Expand All @@ -104,14 +104,14 @@ def [](*list)
# If we passed a variadic list of Strings, `*list` will make it a single `Array<String>` and we were already good to go.
# But if we passed an Array, `*list` will make it an Array<Array<String>> of one item; taking `list.first` will go back to Array<String>.
list = list.first if list.count == 1 && list.first.is_a?(Array)
from_glotpress(list)
from_glotpress!(list)
end

# Return the subset of the 16 locales most of our apps are localized 100% (the ones we call the "Magnificent 16")
#
# @return [Array<Locale>] List of the Mag16 locales
def mag16
from_glotpress(MAG16_GP_CODES)
from_glotpress!(MAG16_GP_CODES)
end

###################
Expand Down
12 changes: 6 additions & 6 deletions spec/locales_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe Fastlane::Locales do
shared_examples 'from_xxx' do |key, fr_code, pt_code|
let(:method_sym) { "from_#{key}".to_sym }
let(:method_sym) { "from_#{key}!".to_sym }

it 'can find a locale from a single code' do
fr_locale = described_class.send(method_sym, fr_code)
Expand Down Expand Up @@ -30,23 +30,23 @@
end
end

describe 'from_glotpress' do
describe 'from_glotpress!' do
include_examples 'from_xxx', :glotpress, 'fr', 'pt-br'
end

describe 'from_android' do
describe 'from_android!' do
include_examples 'from_xxx', :android, 'fr', 'pt-rBR'
end

describe 'from_google_play' do
describe 'from_google_play!' do
include_examples 'from_xxx', :google_play, 'fr-FR', 'pt-BR'
end

describe 'from_ios' do
describe 'from_ios!' do
include_examples 'from_xxx', :ios, 'fr-FR', 'pt-BR'
end

describe 'from_app_store' do
describe 'from_app_store!' do
include_examples 'from_xxx', :app_store, 'fr-FR', 'pt-BR'
end

Expand Down

0 comments on commit 8204b59

Please sign in to comment.