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
(also: #seed)
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.
4 5 6 |
# File 'lib/seed-fu-ndo/seeder.rb', line 4 def model_class @model_class end |
Instance Method Details
#existing_records ⇒ Object
List of the seeded records that exist in the database.
28 29 30 |
# File 'lib/seed-fu-ndo/seeder.rb', line 28 def existing_records @data.map { |record_data| find_record(record_data.symbolize_keys) }.compact end |
#seed_with_undo ⇒ Object Also known as: seed
Record instead of inserting the data if in recording mode.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/seed-fu-ndo/seeder.rb', line 7 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.
21 22 23 24 25 |
# File 'lib/seed-fu-ndo/seeder.rb', line 21 def unseed @model_class.transaction do existing_records.reverse.each { |record| unseed_record(record) } end end |