Method: ConfigScripts::Seeds::SeedType#write_to_folder
- Defined in:
- lib/config_scripts/seeds/seed_type.rb
#write_to_folder(folder) ⇒ Object
This method writes the seed data file to a folder.
This will write a header row with the names of the attributes, and then write a row for each item from the #items method. It will use the #write_value_for_attribute method to get the values for the CSV file.
If this seed type has no attributes, this method will not write anything.
179 180 181 182 183 184 185 186 187 188 |
# File 'lib/config_scripts/seeds/seed_type.rb', line 179 def write_to_folder(folder) return unless attributes.any? CSV.open(File.join(folder, "#{self.filename}.csv"), 'w') do |csv| csv << self.attributes self.items.each do |item| data = self.attributes.collect { |attribute| self.write_value_for_attribute(item, attribute) } csv << data end end end |