Project

seedfile

0.0
No commit activity in last 3 years
No release in over 3 years
Create ActiveRecord objects using a CSV file
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.14.0
~> 1.3.8

Runtime

>= 3.2.0
 Project Readme

Seedfile

Create ActiveRecord objects using a CSV file.

Usage

As an example, let's use the following CSV file and Car class to seed the database. The first row of the CSV file must be the attribute names.

data.csv

Brand,Model,Year,Price
BMW,3 Series,2014,32750
Mercedes-Benz,CLA-Class,2014,29990
Audi,A4,2014,33800

car.rb

class Car < ActiveRecord::Base
end

Nothing in the database.

>> Car.all
=> #<ActiveRecord::Relation []>

Create a new Seedfile instance. Pass in the path to the CSV and the model.

>> data = Seedfile.new(path: 'data.csv', model: Car)

Seed it.

>> data.seed

Database is populated with data from the file.

>> Car.all
=> #<ActiveRecord::Relation [#<Car id: 1, brand: "BMW", model: "3 Series", year: 2014, price: 32750>, #<Car id: 2, brand: "Mercedes-Benz", model: "CLA-Class", year: 2014, price: 29990>, #<Car id: 3, brand: "Audi", model: "A4", year: 2014, price: 33800>]>