Class: Seedie::Seeder

Inherits:
Object
  • Object
show all
Includes:
Reporters::Reportable
Defined in:
lib/seedie/seeder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Reporters::Reportable

#add_observers, #report

Constructor Details

#initialize(config_path = nil) ⇒ Seeder

Returns a new instance of Seeder.



9
10
11
12
13
14
15
16
17
# File 'lib/seedie/seeder.rb', line 9

def initialize(config_path = nil)
  @config_path = config_path
  @config = load_config(config_path)
  @reporters = []
  @console_reporter = Reporters::ConsoleReporter.new
  @reporters << @console_reporter

  add_observers(@reporters)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/seedie/seeder.rb', line 7

def config
  @config
end

Instance Method Details

#seed_modelsObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/seedie/seeder.rb', line 19

def seed_models
  report(:seed_start)
  ActiveRecord::Base.transaction do
    config["models"].each do |model_name, model_config|
      model = model_name.classify.constantize
      ModelSeeder.new(model, model_config, config, @reporters).generate_records
    end
  end
  report(:seed_finish)

  @reporters.each(&:close)
end