Class: SeedFu::Seeder

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#model_classObject (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_recordsObject

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_undoObject 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

#unseedObject

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