lib/aka/upgrader.rb in hsume2-aka-0.2.1 vs lib/aka/upgrader.rb in hsume2-aka-0.3.0

- old
+ new

@@ -1,23 +1,47 @@ module Aka module Upgrader - module FromV0 + module FromV0ToV1 def self.run(aka_yml) v0 = YAML::load_file(aka_yml) current = { - :version => Aka::Configuration::FORMAT, + :version => '1', :shortcuts => v0 } FileUtils.cp(aka_yml, "#{aka_yml}.backup") + puts "Backed up to #{aka_yml}.backup." File.open(aka_yml, 'w+') do |f| f.write current.to_yaml end - puts "Upgraded #{aka_yml}." + end + end + + module FromV1ToV2 + def self.run(aka_yml) + v1 = YAML::load_file(aka_yml) + + v2 = v1.merge(:version => '2') + links = v2.delete(:links) + v2[:links] = new_links = {} + if links + index = 0 + links.each do |element| + index += 1 + new_links[index] = element + end + end + + FileUtils.cp(aka_yml, "#{aka_yml}.backup") puts "Backed up to #{aka_yml}.backup." + + File.open(aka_yml, 'w+') do |f| + f.write v2.to_yaml + end + puts "Upgraded #{aka_yml}." end end end end