Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Further simplified YAML code

  • Loading branch information...
commit cf41fb1860f3d1215c3136ec85717e57b7a095ba 1 parent 6ced31c
@konklone konklone authored
Showing with 5 additions and 8 deletions.
  1. +5 −8 Rakefile
View
13 Rakefile
@@ -16,14 +16,12 @@ namespace :data do
desc "Restore a model using YAML backup"
task :restore => :environment do
model = ENV['model'].singularize.camelize.constantize
- filename = "%s.yml" % File.join("data", model.table_name)
-
model.delete_all
- YAML::load_file(filename).each do |data_row|
+ YAML::load_file("data/#{model.table_name}.yml").each do |row|
record = model.new
- data_row.keys.each do |field|
- record[field] = data_row[field] if data_row[field]
+ row.keys.each do |field|
+ record[field] = row[field] if row[field]
end
record.save
end
@@ -33,7 +31,6 @@ namespace :data do
desc "Backup a model to YAML."
task :backup => :environment do
model = ENV['model'].singularize.camelize.constantize
- filename = "%s.yml" % File.join("data", model.table_name)
data = model.all.reduce([]) do |records, record|
element = {}
@@ -43,8 +40,8 @@ namespace :data do
records << element
end
- FileUtils.mkdir_p File.dirname(filename)
- File.open(filename, "w") do |file|
+ FileUtils.mkdir_p "data"
+ File.open("data/#{model.table_name}.yml", "w") do |file|
YAML.dump data, file
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.