Class: SeedDumper::Fetcher
- Inherits:
-
Object
- Object
- SeedDumper::Fetcher
- Defined in:
- lib/seed_dumper/fetcher.rb
Overview
Dumper
Class Method Summary collapse
Class Method Details
.fetch_data(klass, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/seed_dumper/fetcher.rb', line 6 def self.fetch_data(klass, ={}) ignore = ['created_at', 'updated_at'] model_name = klass.name puts "Adding #{model_name.camelize} seeds." records = klass.all.map do |record| attr_s = []; record.attributes.delete_if { |k, v| ignore.include?(k) }.each do |key, value| value = value.class == Time ? "\"#{value}\"" : value.inspect value = nil if value.is_a?(String) && value == "\"\"" value = nil if value == 'nil' || value == "nil" unless value.nil? attr_s.push("#{key.to_sym.inspect} => #{value}")# unless key == 'id' end end "#{model_name.camelize}.create(#{attr_s.join(', ')})" end # / records.each_with_index records end |