Class: MobilityActiveStorage::BackendMethods::FallbackChain

Inherits:
Object
  • Object
show all
Defined in:
lib/mobility_active_storage/backend_methods.rb,
sig/mobility_active_storage.rbs

Overview

Resolves a locale to the chain of locales to try, in order.

Mirrors Mobility's own fallbacks plugin: an explicit map is honoured first, then I18n's configured fallbacks when the application has them enabled, and the default locale always terminates the chain. Resolved on each read so that changes to I18n.default_locale or I18n.fallbacks are picked up.

Instance Method Summary collapse

Constructor Details

#initialize(map) ⇒ FallbackChain

Returns a new instance of FallbackChain.

Parameters:

  • map (Hash[Symbol, untyped])


92
93
94
# File 'lib/mobility_active_storage/backend_methods.rb', line 92

def initialize(map)
  @fallbacks = I18n::Locale::Fallbacks.new(map)
end

Instance Method Details

#[](locale) ⇒ Array[Symbol]

Parameters:

  • locale (Symbol)

Returns:

  • (Array[Symbol])


96
97
98
99
100
# File 'lib/mobility_active_storage/backend_methods.rb', line 96

def [](locale)
  chain = @fallbacks[locale]
  chain |= I18n.fallbacks[locale] if I18n.respond_to?(:fallbacks)
  chain | [I18n.default_locale]
end