Class: C11n::Synchronizer

Inherits:
Object
  • Object
show all
Defined in:
lib/c11n/synchronizer.rb,
lib/c11n/synchronizer/ios.rb,
lib/c11n/synchronizer/rails.rb,
lib/c11n/synchronizer/android.rb

Defined Under Namespace

Classes: Android, Ios, Rails

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Synchronizer

Returns a new instance of Synchronizer.



22
23
24
25
# File 'lib/c11n/synchronizer.rb', line 22

def initialize(options = {})
  @configuration = options[:configuration]
  @translations = C11n::Translations.new
end

Instance Method Details

#downloadObject



42
43
44
45
46
47
48
# File 'lib/c11n/synchronizer.rb', line 42

def download
  @translations.import_with(google_drive_importer)

  project.exporters.each do |locale, exporter|
    @translations.export_with(exporter, locale)
  end
end

#google_drive_exporterObject



31
32
33
# File 'lib/c11n/synchronizer.rb', line 31

def google_drive_exporter
  @google_drive_exporter ||= C11n::Exporter::GoogleDrive.new
end

#google_drive_importerObject



27
28
29
# File 'lib/c11n/synchronizer.rb', line 27

def google_drive_importer
  @google_drive_importer ||= C11n::Importer::GoogleDrive.new
end

#projectObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/c11n/synchronizer.rb', line 11

def project
  @project ||= case @configuration.type
  when 'ios'
    C11n::Synchronizer::Ios.new(@configuration.to_hash)
  when 'android'
    C11n::Synchronizer::Android.new(@configuration.to_hash)
  when 'rails'
    C11n::Synchronizer::Rails.new(@configuration.to_hash)
  end
end

#setupObject



50
51
52
53
54
55
56
# File 'lib/c11n/synchronizer.rb', line 50

def setup
  schema = [C11n::Table::CATEGORY_COLUMN, C11n::Table::KEY_COLUMN, C11n::Table::TYPE_COLUMN] + project.importers.keys.map(&:to_s)

  table_with_schema = C11n::Table.new([schema])

  google_drive_exporter.export_table(table_with_schema)
end

#uploadObject



35
36
37
38
39
40
# File 'lib/c11n/synchronizer.rb', line 35

def upload
  project.importers.each do |locale, importer|
    @translations.import_with(importer)
    @translations.export_with(google_drive_exporter, locale)
  end
end