Module: Sequel::Extensions::FromCsv
- Defined in:
- lib/sequel/extensions/from_csv.rb
Instance Method Summary collapse
-
#seed_from_csv(directory, **opts) ⇒ Object
Finds all CSV files in a directory and synchronizes with their respective DB tables.
Instance Method Details
#seed_from_csv(directory, **opts) ⇒ Object
Finds all CSV files in a directory and synchronizes with their respective DB tables
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/sequel/extensions/from_csv.rb', line 6 def seed_from_csv directory, **opts Dir.glob("#{directory}/**/*.csv").each do |filename| klass = filename.sub "#{directory}", "" klass = klass[1..-1] if klass.starts_with? "/" klass = klass.split(".")[0] model = klass.classify.constantize model.plugin :from_csv model.seed_from_csv filename, **opts end nil end |