Last active
August 29, 2015 14:10
-
-
Save ulissesalmeida/54a5c26a5cf903316111 to your computer and use it in GitHub Desktop.
Dump yml in to files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class YamlDump | |
def dump! | |
dump(Race) | |
dump(Background) | |
dump(CharacterClass) | |
end | |
private | |
def dump(klass) | |
folder = klass.name.underscore.downcase.pluralize | |
klass.all.each do |object| | |
write(folder, object[:slug], object.to_yaml) | |
end | |
end | |
def write(folder, slug, contents) | |
filename = Rails.root.join('config', 'seeds', folder, "#{slug}.yml") | |
File.open(filename, 'w+') { |f| f.write(contents) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment