Class: SgtnClient::TranslationLoader::Chain

Inherits:
Object
  • Object
show all
Defined in:
lib/sgtn-client/loader/chain_loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*loaders) ⇒ Chain

Returns a new instance of Chain.



9
10
11
# File 'lib/sgtn-client/loader/chain_loader.rb', line 9

def initialize(*loaders)
  self.loaders = loaders
end

Instance Attribute Details

#loadersObject

Returns the value of attribute loaders.



7
8
9
# File 'lib/sgtn-client/loader/chain_loader.rb', line 7

def loaders
  @loaders
end

Instance Method Details

#available_bundlesObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sgtn-client/loader/chain_loader.rb', line 29

def available_bundles
  exception = nil
  total_data = Set.new

  loaders.each do |loader|
    begin
      item = loader.available_bundles
      total_data += item
    rescue StandardError => e
      exception = e
      SgtnClient.logger.error "[#{__FILE__}][#{__callee__}] failed on #{loader.class}: #{e}"
    end
  end

  raise exception if total_data.empty? && exception

  total_data
end

#load_bundle(component, locale) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sgtn-client/loader/chain_loader.rb', line 13

def load_bundle(component, locale)
  exception = nil

  loaders.each do |loader|
    begin
      bundle = loader.load_bundle(component, locale)
      return bundle if bundle
    rescue StandardError => e
      exception = e
      SgtnClient.logger.error "[#{__FILE__}][#{__callee__}] {component: #{component},locale: #{locale}}, failed on #{loader.class}: #{e}"
    end
  end

  raise exception || SgtnClient::SingletonError.new("can't load component: #{component}, locale: #{locale}")
end