Sha256: 6f1b16aa094074e280a834aedfde364f37704de6b88cdadf07b9f0a0ac71a7e5

Contents?: true

Size: 1.13 KB

Versions: 22

Compression:

Stored size: 1.13 KB

Contents

namespace :reso do

  desc "Populate database with seed data."
  task :seed => [:load_enumerations, :seed_imports] 

  task :load_enumerations => [:environment] do
    require "csv"
    csv_text = File.read("#{Rails.root}/db/enumerations.csv")
    csv = CSV.parse(csv_text, :headers => true)
    csv.each do |row|
      row = row.to_hash.with_indifferent_access
      Enumeration.find_or_create_by(row.to_hash.symbolize_keys)
        puts row.inspect
      end
      puts
  end

  task :seed_imports => [:environment] do
    imports = [{ name: "RESO Example", 
                 token: "reso",
                 import_format_id: ImportFormat.find_by(name: 'reso').id,
                 source_url: "https://app.listhub.com/syndication-docs/example.xml"
              }]
  
    imports.each do |import|
      @import = Import.new
      import.each_pair{|key, value| @import[key] = value }
      @import.save
    end
  end

  desc "Download and import data file for specified import."
  task :import, [:import_token] => [:environment] do |t, args|
    args.with_defaults(:import_token => "reso")
    Import.find_by(token: args.import_token).run_import
  end

end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
reso-0.1.6.7 lib/reso/railties/reso.rake
reso-0.1.6.6 lib/reso/railties/reso.rake
reso-0.1.6.5 lib/reso/railties/reso.rake
reso-0.1.6.4 lib/reso/railties/reso.rake
reso-0.1.6.3 lib/reso/railties/reso.rake
reso-0.1.6.2 lib/reso/railties/reso.rake
reso-0.1.6.1 lib/reso/railties/reso.rake
reso-0.1.6 lib/reso/railties/reso.rake
reso-0.1.5.11 lib/reso/railties/reso.rake
reso-0.1.5.10 lib/reso/railties/reso.rake
reso-0.1.5.9 lib/reso/railties/reso.rake
reso-0.1.5.7 lib/reso/railties/reso.rake
reso-0.1.5.6 lib/reso/railties/reso.rake
reso-0.1.5.5 lib/reso/railties/reso.rake
reso-0.1.5.4 lib/reso/railties/reso.rake
reso-0.1.5.3 lib/reso/railties/reso.rake
reso-0.1.5.2 lib/reso/railties/reso.rake
reso-0.1.5.1 lib/reso/railties/reso.rake
reso-0.1.5.0 lib/reso/railties/reso.rake
reso-0.1.4.10 lib/reso/railties/reso.rake