Class: I18n::Migrations::Migrator

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n/migrations/migrator.rb

Instance Method Summary collapse

Instance Method Details

#configObject



29
30
31
# File 'lib/i18n/migrations/migrator.rb', line 29

def config
  @config ||= Config.new.read!
end

#config=(config) ⇒ Object

for testing



34
35
36
# File 'lib/i18n/migrations/migrator.rb', line 34

def config=(config)
  @config = config
end

#locale_for(name) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/i18n/migrations/migrator.rb', line 21

def locale_for(name)
  Locale.new(name,
             locales_dir: config.locales_dir,
             main_locale_name: config.main_locale,
             migrations: new_migrations,
             dictionary: new_dictionary(name))
end

#migrate(locale_or_all = 'all') ⇒ Object



61
62
63
64
65
# File 'lib/i18n/migrations/migrator.rb', line 61

def migrate(locale_or_all = 'all')
  each_locale(locale_or_all) do |locale|
    locale.migrate!
  end
end

#new_locale(new_locale) ⇒ Object



90
91
92
# File 'lib/i18n/migrations/migrator.rb', line 90

def new_locale(new_locale)
  locale_for(new_locale).create
end

#new_migration(name) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/i18n/migrations/migrator.rb', line 38

def new_migration(name)
  name = name.parameterize(separator: '_')
  time = Time.now.strftime('%Y%m%d%H%M')
  file_name = "#{time}_#{name.downcase.gsub(' ', '_')}.rb"
  unless Dir.exist?(config.migration_dir)
    puts "Creating migration directory #{config.migration_dir} because it didn't exist."
    FileUtils.mkdir_p(config.migration_dir)
  end
  full_file_name = File.join(config.migration_dir, file_name)
  File.open(full_file_name, 'w') do |f|
    f << <<-CONTENTS
require 'i18n-migrations'

class #{name.camelcase}#{time} < I18n::Migrations::Migration
  def change
    # add('foo.bar', 'The foo of the bar')
  end
end
    CONTENTS
  end
  puts "Wrote new migration to #{full_file_name}"
end

#pull(locale_or_all) ⇒ Object



75
76
77
78
79
80
# File 'lib/i18n/migrations/migrator.rb', line 75

def pull(locale_or_all)
  each_locale(locale_or_all) do |locale|
    # next if locale.main_locale?
    backend.pull(locale)
  end
end

#push(locale_or_all, force = false) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/i18n/migrations/migrator.rb', line 82

def push(locale_or_all, force = false)
  backend.sync_migrations(new_migrations)
  each_locale(locale_or_all, concurrency: config.push_concurrency) do |locale|
    backend.push(locale, force: force)
    wait
  end
end

#rollback(locale_or_all) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/i18n/migrations/migrator.rb', line 67

def rollback(locale_or_all)
  each_locale(locale_or_all) do |locale|
    locale.update_info do |data, |
      locale.rollback(data, )
    end
  end
end

#validate(locale_or_all) ⇒ Object



100
101
102
103
104
105
106
107
# File 'lib/i18n/migrations/migrator.rb', line 100

def validate(locale_or_all)
  each_locale(locale_or_all, async: false) do |locale|
    next if locale.main_locale?
    locale.update_info do |data, |
      locale.validate(data, )
    end
  end
end

#versionObject



94
95
96
97
98
# File 'lib/i18n/migrations/migrator.rb', line 94

def version
  each_locale do |locale|
    puts "#{locale.name}: #{locale.last_version}"
  end
end