Class: FactoryBotFactory::BaseFactory
- Inherits:
-
Object
- Object
- FactoryBotFactory::BaseFactory
- Defined in:
- lib/factory_bot_factory/factories/base_factory.rb
Direct Known Subclasses
Instance Method Summary collapse
- #generate(data) ⇒ Object
-
#initialize(options = {}) ⇒ BaseFactory
constructor
A new instance of BaseFactory.
Constructor Details
#initialize(options = {}) ⇒ BaseFactory
Returns a new instance of BaseFactory.
4 5 6 7 8 9 10 |
# File 'lib/factory_bot_factory/factories/base_factory.rb', line 4 def initialize( = {}) @factory_name = [:factory_name] @file_path = [:file_path] @nested_level = [([:nested_level] || 1), 5].min @line_writer = LineWriter.new() @factory_queue = [] end |
Instance Method Details
#generate(data) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/factory_bot_factory/factories/base_factory.rb', line 12 def generate(data) output = LineWriter.wrap_definition do push_to_factory_queue(@factory_name, data, @nested_level) inner_output = [] loop do factory_option = @factory_queue.shift inner_output += build_factory(*factory_option) break if @factory_queue.empty? inner_output << LineWriter::WHITE_SPACE end inner_output end.join(LineWriter::NEW_LINE) write_to_file(output) output end |