module SeedPacket
Constants
- VERSION
Attributes
environment[RW]
factory_class[RW]
Public Class Methods
new(environment: nil, factory_class: 'FactoryBot')
click to toggle source
rubocop:disable Metrics/LineLength
# File lib/seed_packet.rb, line 12 def initialize(environment: nil, factory_class: 'FactoryBot') self.environment = environment ? Environment.new(environment) : nil self.factory_class = Object.const_get(factory_class) if self.environment.samples_allowed? end
Public Instance Methods
sample() { || ... }
click to toggle source
# File lib/seed_packet.rb, line 23 def sample yield if environment.samples_allowed? end
scrub() { || ... }
click to toggle source
# File lib/seed_packet.rb, line 27 def scrub yield if environment.scrubbing_allowed? end
seed() { || ... }
click to toggle source
rubocop:enable Metrics/LineLength
# File lib/seed_packet.rb, line 19 def seed yield if environment.seeding_allowed? end
Private Instance Methods
sow_seeds(factory, display_items: false, count: rand(20), traits: [], values: {}, message: '')
click to toggle source
rubocop:disable Metrics/ParameterLists, Style/FormatStringToken
# File lib/seed_packet.rb, line 34 def sow_seeds(factory, display_items: false, count: rand(20), traits: [], values: {}, message: '') return unless environment.seeding_allowed? sample_factory_name = "#{factory}_sample" sample_items = factory_class.create_list(sample_factory_name, count, *traits, values) if display_items sample_items.each do |item| pp item.attributes puts end end item_class_name = sample_items.first.class.name log_message = '%4s %s Created %s' % [ count, item_class_name .underscore .titleize .pluralize, message, ] print "#{' ' * 100}\r#{log_message}\r" sample_items end