Sha256: 2f0ad456ad975ead37ce05bba8971ddf9ed39fdb70b876373cec599ece74a551
Contents?: true
Size: 1.05 KB
Versions: 5
Compression:
Stored size: 1.05 KB
Contents
# frozen_string_literal: true namespace :mr_common do desc "dump reminders" task dump_reminders: :environment do reminders = Reminder.all.map do |r| r.attributes end unless reminders.any? puts "No reminders to save yet..." exit end yml = reminders.to_yaml file = File.open("reminders.yml", "w") file.write(yml) file.close end desc "load reminders" task load_reminders: :environment do unless Dir["reminders.yml"].any? puts "No reminders to load yet..." exit end reminders = YAML.load(File.read("reminders.yml")) if reminders.any? reminder_fields = %i[ all_day description end_time location start_time summary time_zone include_in_confirmation_mailer ] reminders.each do |reminder| r = Reminder.find_or_initialize_by(slug: reminder["slug"]) attrs = {} reminder_fields.each { |attr| attrs[attr.to_s] = reminder[attr.to_s] } r.update(attrs) end end end end
Version data entries
5 entries across 5 versions & 1 rubygems