Class: TranslationDiff::Languages::Refresh

Inherits:
Object
  • Object
show all
Defined in:
lib/translation_diff/languages/refresh.rb

Overview

A maintainer's tool: re-fetches every provider's lists and rewrites the shipped files.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(providers:, directory:, on:) ⇒ Refresh

Returns a new instance of Refresh.



7
8
9
10
11
# File 'lib/translation_diff/languages/refresh.rb', line 7

def initialize(providers:, directory:, on:)
  @providers = providers
  @directory = directory
  @on = on
end

Class Method Details

.call(providers:, directory: TranslationDiff::Languages::DIRECTORY, on: Time.now.strftime("%Y-%m-%d")) ⇒ Object



3
4
5
# File 'lib/translation_diff/languages/refresh.rb', line 3

def self.call(providers:, directory: TranslationDiff::Languages::DIRECTORY, on: Time.now.strftime("%Y-%m-%d"))
  new(providers: providers, directory: directory, on: on).call
end

Instance Method Details

#call ⇒ Object

A provider whose fetch fails keeps its previous file: an emptied list is worse than a stale one.



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/translation_diff/languages/refresh.rb', line 14

def call
  report = { updated: [], failed: {}, skipped: [] }

  @providers.each do |provider|
    name = provider.cache_key
    fetched = fetch(provider, name, report)
    next if fetched.nil?

    persist(name, provider, fetched, report)
  end

  report
end