Class: BetterSeeder::Exporters::Csv
- Defined in:
- lib/better_seeder/exporters/csv.rb
Instance Attribute Summary
Attributes inherited from Base
#data, #output_path, #table_name
Instance Method Summary collapse
-
#export ⇒ Object
Esporta i dati in formato CSV e li salva in un file nella cartella “db/seed/preload”.
- #extension ⇒ Object
Methods inherited from Base
#ensure_output_directory, #full_output_path, #initialize, #output_directory
Constructor Details
This class inherits a constructor from BetterSeeder::Exporters::Base
Instance Method Details
#export ⇒ Object
Esporta i dati in formato CSV e li salva in un file nella cartella “db/seed/preload”. Se la cartella non esiste, viene creata automaticamente.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/better_seeder/exporters/csv.rb', line 8 def export return if data.empty? headers = data.first.keys # Costruisce il percorso completo del file di output full_path = File.join(full_output_path) CSV.open(full_path, 'w', write_headers: true, headers: headers) do |csv| data.each { |row| csv << row.values } end end |
#extension ⇒ Object
21 22 23 |
# File 'lib/better_seeder/exporters/csv.rb', line 21 def extension '.csv' end |