Sha256: 6786049bcacf69f6e49e6ab69e3935c36f6dce51ac3408e633063fd77c9d0045

Contents?: true

Size: 651 Bytes

Versions: 6

Compression:

Stored size: 651 Bytes

Contents

namespace :db do

  namespace :seed do

    desc "Create CSV Files for Models"
    task :create_files => :environment do
      Dir.glob("#{Rails.root}/app/models/*.rb").each { |file| require file }
      dir = "#{Rails.root}/db/csv"
      FileUtils.mkdir(dir) unless File.exists?(dir)
      ActiveRecord::Base.descendants.each do |model|
        unless File.exists?("#{dir}/#{model.to_s.tableize}.csv")
          File.open("#{dir}/#{model.to_s.tableize}.csv", 'w+') do |f| 
            f.write(model.columns.collect(&:name).join(','))
          end
          puts "CREATED FILE >> #{model.to_s.tableize}.csv"
        end
      end
    end

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cambium-0.3.0 lib/generators/cambium/templates/lib/tasks/db.rake
cambium-0.2.2 lib/generators/cambium/templates/lib/tasks/db.rake
cambium-0.2.1 lib/generators/cambium/templates/lib/tasks/db.rake
cambium-0.2.0 lib/generators/cambium/templates/lib/tasks/db.rake
cambium-0.0.2 lib/generators/cambium/templates/lib/tasks/db.rake
cambium-0.0.1 lib/generators/cambium/templates/lib/tasks/db.rake