Method: StaticData::Base.update
- Defined in:
- lib/static-data/base.rb
.update ⇒ Object
Creates new records for all of the data returned by the rows method of the StaticData subclass – unless they exist already.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/static-data/base.rb', line 49 def self.update created = 0 existing = 0 cols = self.columns row_class = self.model_class self.rows.each do |row| attribs = Hash[cols.zip(row)] row_class.transaction do if row_class.exists?(attribs) existing += 1 else row_class.create!(attribs, :without_protection => true) created += 1 end end end return {:created => created, :existing => existing} end |