Class: Seedie::ModelSeeder
- Inherits:
-
Object
- Object
- Seedie::ModelSeeder
- Includes:
- Reporters::Reportable
- Defined in:
- lib/seedie/model_seeder.rb
Constant Summary collapse
- DEFAULT_MODEL_COUNT =
1
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#model_config ⇒ Object
readonly
Returns the value of attribute model_config.
-
#reporters ⇒ Object
readonly
Returns the value of attribute reporters.
Instance Method Summary collapse
- #generate_records ⇒ Object
-
#initialize(model, model_config, config, reporters) ⇒ ModelSeeder
constructor
A new instance of ModelSeeder.
Methods included from Reporters::Reportable
Constructor Details
#initialize(model, model_config, config, reporters) ⇒ ModelSeeder
Returns a new instance of ModelSeeder.
11 12 13 14 15 16 17 18 |
# File 'lib/seedie/model_seeder.rb', line 11 def initialize(model, model_config, config, reporters) @model = model @model_config = model_config @config = config @record_creator = Model::Creator.new(model, reporters) @reporters = reporters add_observers(@reporters) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/seedie/model_seeder.rb', line 9 def config @config end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
9 10 11 |
# File 'lib/seedie/model_seeder.rb', line 9 def model @model end |
#model_config ⇒ Object (readonly)
Returns the value of attribute model_config.
9 10 11 |
# File 'lib/seedie/model_seeder.rb', line 9 def model_config @model_config end |
#reporters ⇒ Object (readonly)
Returns the value of attribute reporters.
9 10 11 |
# File 'lib/seedie/model_seeder.rb', line 9 def reporters @reporters end |
Instance Method Details
#generate_records ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/seedie/model_seeder.rb', line 20 def generate_records report(:model_seed_start, name: model.to_s) model_count(model_config).times do |index| record = generate_record(model_config, index) associations_config = model_config["associations"] next unless associations_config.present? Associations::HasMany.new(record, model, associations_config, reporters).generate_associations Associations::HasAndBelongsToMany.new(record, model, associations_config, reporters).generate_associations Associations::HasOne.new(record, model, associations_config, reporters).generate_associations end report(:model_seed_finish, name: model.to_s) end |