Class: SgtnClient::TranslationLoader::Source
- Inherits:
-
Object
- Object
- SgtnClient::TranslationLoader::Source
- Defined in:
- lib/sgtn-client/loader/source.rb
Overview
:nodoc:
Instance Method Summary collapse
- #available_bundles ⇒ Object
-
#initialize(config) ⇒ Source
constructor
A new instance of Source.
- #load_bundle(component, locale = nil) ⇒ Object
Constructor Details
#initialize(config) ⇒ Source
Returns a new instance of Source.
11 12 13 |
# File 'lib/sgtn-client/loader/source.rb', line 11 def initialize(config) @source_bundle_path = Pathname.new(config.source_bundle) end |
Instance Method Details
#available_bundles ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/sgtn-client/loader/source.rb', line 37 def available_bundles SgtnClient.logger.debug { "[#{method(__callee__).owner}.#{__callee__}]" } @available_bundles ||= begin @source_bundle_path.children.select(&:directory?).reduce(Set.new) do |bundles, component| Pathname.glob(component + '**/*.{yml, yaml}') do |_| bundles << Common::BundleID.new(component.basename.to_s, LocaleUtil.get_source_locale) break bundles end || bundles end end end |
#load_bundle(component, locale = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sgtn-client/loader/source.rb', line 15 def load_bundle(component, locale = nil) return if locale && locale != CONSTS::REAL_SOURCE_LOCALE # return when NOT querying source SgtnClient.logger.debug { "[#{method(__callee__).owner}.#{__callee__}] component=#{component}" } = {} Pathname.glob(@source_bundle_path + component + '**/*.{yml, yaml}') do |f| bundle = YAML.load(File.read(f)) = bundle&.first&.last # TODO: Warn about inconsistent source locale if .is_a?(Hash) .merge!() else SgtnClient.logger.error "[#{method(__callee__).owner}.#{__callee__}] invalid bundle data in #{f}" end end raise SingletonError, "no local source messages for component #{component}" if .empty? Common::BundleData.new(, origin: self, component: component, locale: LocaleUtil.get_source_locale) end |