class ToptranslationCli::FileFinder
Public Class Methods
local_files(project)
click to toggle source
# File lib/toptranslation_cli/file_finder.rb, line 14 def local_files(project) ToptranslationCli.configuration.files.each_with_object({}) do |path_definition, mem| project&.locales&.map(&:code)&.each do |locale_code| mem.merge!(local_files_for_path_definition(path_definition, locale_code)) end end end
new(path_definition)
click to toggle source
# File lib/toptranslation_cli/file_finder.rb, line 5 def initialize(path_definition) @path_definition = path_definition end
remote_files(project)
click to toggle source
# File lib/toptranslation_cli/file_finder.rb, line 22 def remote_files(project) project_locales = project&.locales project&.documents&.each_with_object({}) do |document, files| project_locales&.each do |locale| translation = document.translations.find { |t| t.locale.code == locale.code } next unless translation path = document.path.gsub('{locale_code}', locale.code) files[path] = remote_file(document, locale, translation) end end end
Private Class Methods
checksum(path)
click to toggle source
# File lib/toptranslation_cli/file_finder.rb, line 52 def checksum(path) Digest::SHA1.file(path).hexdigest end
local_files_for_path_definition(path_definition, locale_code)
click to toggle source
# File lib/toptranslation_cli/file_finder.rb, line 45 def local_files_for_path_definition(path_definition, locale_code) new(path_definition) .files(locale_code) .map { |path| { path => checksum(path) } } .reduce({}, &:merge) end
remote_file(document, locale, translation)
click to toggle source
# File lib/toptranslation_cli/file_finder.rb, line 37 def remote_file(document, locale, translation) { sha1: translation.sha1, identifier: document.identifier, locale_code: locale.code } end
Public Instance Methods
files(locale_code = '**')
click to toggle source
# File lib/toptranslation_cli/file_finder.rb, line 9 def files(locale_code = '**') Dir.glob(@path_definition.gsub('{locale_code}', locale_code)) end