Class: Seedie::Seeder
- Inherits:
-
Object
- Object
- Seedie::Seeder
- Includes:
- Reporters::Reportable
- Defined in:
- lib/seedie/seeder.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(config_path = nil) ⇒ Seeder
constructor
A new instance of Seeder.
- #seed_models ⇒ Object
Methods included from Reporters::Reportable
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
#config ⇒ Object (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_models ⇒ Object
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 |