Skip to content

Instantly share code, notes, and snippets.

@shekibobo
Last active August 29, 2015 13:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shekibobo/9217202 to your computer and use it in GitHub Desktop.
Save shekibobo/9217202 to your computer and use it in GitHub Desktop.
Convert serialized yaml from syck to psych
require 'yaml'
# original idea comes from http://darwinweb.net/articles/convert-syck-to-psych-yaml-format
namespace :encoding do
desc 'convert serialized Content data from syck yaml serializations to psych'
task :psych => :environment do
content_id = ENV['content_id']
if content_id
convert_data Content.find(content_id)
else
Content.all.each do |content|
convert_data(content)
end
end
puts "Done."
end
end
def convert_data(content)
use_syck
hash = content.data
use_psych
content.update_attributes(data: hash) ? print(".") : print("F(#{content.id})")
end
def use_syck
YAML::ENGINE.yamler = 'syck'
raise "Oops! Something went horribly wrong." unless YAML == Syck
end
def use_psych
YAML::ENGINE.yamler = 'psych'
raise "Oops! Something went horribly wrong." unless YAML == Psych
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment