Class: FactoryBotFactory::BaseFactory
- Inherits:
-
Object
- Object
- FactoryBotFactory::BaseFactory
- Defined in:
- lib/factory_bot_factory/factories/base_factory.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
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.
8 9 10 11 12 13 14 |
# File 'lib/factory_bot_factory/factories/base_factory.rb', line 8 def initialize( = {}) @factory_name = [:factory_name] @file_path = build_file_path([:file_path]) @nested_level = [([:nested_level] || 1), 5].min @line_writer = LineWriter.new() @factory_queue = [] end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
6 7 8 |
# File 'lib/factory_bot_factory/factories/base_factory.rb', line 6 def file_path @file_path end |
Instance Method Details
#generate(data) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/factory_bot_factory/factories/base_factory.rb', line 16 def generate(data) push_to_factory_queue(@factory_name, data, @nested_level) output = [] loop do factory_option = @factory_queue.shift output += build_factory(*factory_option) break if @factory_queue.empty? output << LineWriter::WHITE_SPACE end if @file_path write_file(output) else output = LineWriter.wrap_definition { output } end output ensure FactoryBot.reload if Object.const_defined?("FactoryBot") puts(output) if FactoryBotFactory.config.print_output end |