5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/onoma/migrator/translation.rb', line 5
def run(migration)
puts "Migration #{migration.name}"
I18n.available_locales.each do |locale|
file = Onoma.root.join('config', 'locales', "#{locale.to_s}.yml")
hash = yaml_to_hash(file)
migration.each_action do |action|
ref = hash[locale.to_sym][:nomenclatures]
ref[action.nomenclature.to_sym] ||= {}
ref[action.nomenclature.to_sym][:items] ||= {}
if action.is_a?(Onoma::Migration::Actions::ItemChange) && action.new_name?
ref[action.nomenclature.to_sym][:items][action.new_name.to_sym] ||= ref[action.nomenclature.to_sym][:items].delete(action.name.to_sym)
elsif action.is_a?(Onoma::Migration::Actions::ItemMerging)
ref[action.nomenclature.to_sym][:items].delete(action.name.to_sym)
elsif action.is_a?(Onoma::Migration::Actions::NomenclatureChange) && action.changes[:name]
ref[action.changes[:name].to_sym] = ref.delete(action.nomenclature.to_sym)
elsif action.is_a?(Onoma::Migration::Actions::NomenclatureRemoval)
ref.delete(action.nomenclature.to_sym)
elsif !action.is_a?(Onoma::Migration::Actions::Base)
raise "Cannot handle: #{action.inspect}"
end
File.write(file, hash_to_yaml(hash))
end
end
end
|