Skip to content

Instantly share code, notes, and snippets.

@pilisera
Forked from hchoroomi/syck_to_psych.rb
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pilisera/f563761ebbe437dc448b to your computer and use it in GitHub Desktop.
Save pilisera/f563761ebbe437dc448b to your computer and use it in GitHub Desktop.
require 'yaml'
require 'syck'
require 'fileutils'
if ARGV.empty?
$stderr.puts "! Must pass one or more filenames to convert from Syck output to Psych output."
exit 1
end
bad_files = ARGV.select{ |f| ! File.exists?(f) }
if bad_files.any?
$stderr.puts "! Aborting because the following files do not exist:"
$stderr.puts bad_files
exit 1
end
ARGV.each do |filename|
$stdout.print "Converting #{filename} from Syck to Psych..."
hash = Syck.load(File.read filename)
FileUtils.cp filename, "#{filename}.bak"
File.open(filename, 'w'){ |file| file.write(Psych.dump(hash)) }
$stdout.puts " done."
end
@pilisera
Copy link
Author

Forked to work on ruby 2, where you need to require 'syck'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment