Skip to content

Instantly share code, notes, and snippets.

@ulissesalmeida
Last active August 29, 2015 14:10
Show Gist options
  • Save ulissesalmeida/54a5c26a5cf903316111 to your computer and use it in GitHub Desktop.
Save ulissesalmeida/54a5c26a5cf903316111 to your computer and use it in GitHub Desktop.
Dump yml in to files
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