Class: SeedFu::Seeder
- Inherits:
-
Object
- Object
- SeedFu::Seeder
- Defined in:
- lib/seed-fu-ndo/seeder.rb
Overview
Enhanced class from Seed Fu to allow for recording and destroying seed data.
Instance Attribute Summary collapse
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
Instance Method Summary collapse
-
#existing_records ⇒ Object
List of the seeded records that exist in the database.
-
#seed_with_undo ⇒ Object
Record instead of inserting the data if in recording mode.
-
#unseed ⇒ Object
Destroy the seed data.
Instance Attribute Details
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class.
6 7 8 |
# File 'lib/seed-fu-ndo/seeder.rb', line 6 def model_class @model_class end |
Instance Method Details
#existing_records ⇒ Object
List of the seeded records that exist in the database.
29 30 31 |
# File 'lib/seed-fu-ndo/seeder.rb', line 29 def existing_records @data.map { |record_data| find_record(record_data.symbolize_keys) }.compact end |
#seed_with_undo ⇒ Object
Record instead of inserting the data if in recording mode.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/seed-fu-ndo/seeder.rb', line 9 def seed_with_undo if r = SeedFuNdo.recorder r.record self # return existing records in case they are processed by the caller @data.map { |record_data| find_record(record_data) } else seed_without_undo end end |
#unseed ⇒ Object
Destroy the seed data.
22 23 24 25 26 |
# File 'lib/seed-fu-ndo/seeder.rb', line 22 def unseed @model_class.transaction do existing_records.reverse.each { |record| unseed_record(record) } end end |