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.



11
12
13
# File 'lib/sgtn-client/loader/chain_loader.rb', line 11

def initialize(*loaders)
  @loaders = loaders
end

Instance Attribute Details

#loadersObject (readonly)

Returns the value of attribute loaders.



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

def loaders
  @loaders
end

Instance Method Details

#available_bundlesObject



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

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



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

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 || SingletonError.new("can't load component: #{component}, locale: #{locale}")
end