class Fixturama::Changes::Seed

@private Seed objects using the FactoryBot

Public Class Methods

new(**options) click to toggle source
   # File lib/fixturama/changes/seed.rb
 9 def initialize(**options)
10   @type   = type_from(options)
11   @traits = traits_from(options)
12   @params = params_from(options)
13   @count  = count_from(options)
14   create_object
15 end

Private Instance Methods

count_from(options) click to toggle source
   # File lib/fixturama/changes/seed.rb
30 def count_from(options)
31   options.fetch(:count, 1).to_i.tap { |val| return val if val.positive? }
32   raise Fixturama::FixtureError.new("a valid number of objects", options)
33 end
create_object() click to toggle source
   # File lib/fixturama/changes/seed.rb
35 def create_object
36   FactoryBot.create_list(@type, @count, *@traits, **@params)
37 end
params_from(options) click to toggle source
   # File lib/fixturama/changes/seed.rb
26 def params_from(options)
27   Hash(options[:params]).transform_keys(&:to_sym)
28 end
traits_from(options) click to toggle source
   # File lib/fixturama/changes/seed.rb
22 def traits_from(options)
23   Array(options[:traits]).map(&:to_sym)
24 end
type_from(options) click to toggle source
   # File lib/fixturama/changes/seed.rb
17 def type_from(options)
18   options[:type]&.to_sym&.tap { |value| return value }
19   raise Fixturama::FixtureError.new("a factory", options)
20 end