class Translator::Synchronizer

Attributes

output_stream[R]
paths[R]

Public Class Methods

new(paths, output_stream = Translator.output_stream) click to toggle source
# File lib/translator/synchronizer.rb, line 6
def initialize(paths, output_stream = Translator.output_stream)
  @paths = (Array(paths) + Translator.default_file_paths).uniq
  @output_stream = output_stream || Translator.default_output_stream
end

Public Instance Methods

process() click to toggle source
# File lib/translator/synchronizer.rb, line 11
def process
  push
  update
end

Private Instance Methods

pull() click to toggle source
# File lib/translator/synchronizer.rb, line 38
def pull
  require 'fileutils'
  FileUtils.mkdir_p(Translator.data_directory)
  FileUtils.mkdir_p(Pathname.new(Translator.synchronization_data_file).parent)
  File.open(Translator.synchronization_data_file, 'w') { }
  puller.execute
end
pulled?() click to toggle source
# File lib/translator/synchronizer.rb, line 46
def pulled?
  File.exist?(resolve_path(Translator.synchronization_data_file))
end
puller() click to toggle source
# File lib/translator/synchronizer.rb, line 21
def puller
  @puller ||= Localeapp::CLI::Pull.new(output: output_stream)
end
push() click to toggle source
# File lib/translator/synchronizer.rb, line 29
def push
  paths.each { |path| pusher.execute(path)  }
end
pusher() click to toggle source
# File lib/translator/synchronizer.rb, line 17
def pusher
  @pusher ||= ::Localeapp::CLI::Push.new(output: output_stream)
end
resolve_path(path) click to toggle source
# File lib/translator/synchronizer.rb, line 50
def resolve_path(path)
  File.expand_path(path, __FILE__)
end
update() click to toggle source
# File lib/translator/synchronizer.rb, line 33
def update
  pull unless pulled?
  updator.execute
end
updator() click to toggle source
# File lib/translator/synchronizer.rb, line 25
def updator
  @updator ||= Localeapp::CLI::Update.new(output: output_stream)
end