Class: RemoteTranslationLoader::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/remote_translation_loader/loader.rb

Instance Method Summary collapse

Constructor Details

#initialize(urls, fetcher: Fetchers::HttpFetcher.new) ⇒ Loader

Returns a new instance of Loader.



5
6
7
8
# File 'lib/remote_translation_loader/loader.rb', line 5

def initialize(urls, fetcher: Fetchers::HttpFetcher.new)
  @urls = urls
  @fetcher = fetcher
end

Instance Method Details

#fetch_and_load(dry_run: false, namespace: nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/remote_translation_loader/loader.rb', line 10

def fetch_and_load(dry_run: false, namespace: nil)
  @urls.each do |url|
    content = @fetcher.fetch(url)
    validate_translations!(content)

    if dry_run
      puts "Simulating loading for #{url}: #{content.inspect}"
    else
      merge_into_i18n(content, namespace: namespace)
    end
  end
end