Class: FactoryBotFactory::OpenStructFactory

Inherits:
BaseFactory
  • Object
show all
Defined in:
lib/factory_bot_factory/factories/open_struct_factory.rb

Instance Method Summary collapse

Methods inherited from BaseFactory

#generate, #initialize

Constructor Details

This class inherits a constructor from FactoryBotFactory::BaseFactory

Instance Method Details

#build_factory(name, value, level) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/factory_bot_factory/factories/open_struct_factory.rb', line 5

def build_factory(name, value, level)
  output = LineWriter.wrap_factory(name, 'OpenStruct') do
    inner_output = []
    value = value.attributes if value.respond_to?(:attributes)
    value = value.to_h if value.respond_to?(:to_h)
    value.each do |key, value|
      value = build_nested_attribute(name, key, value, 1, level)
      inner_output += value
      inner_output
    end
    inner_output << "to_create {}"
  end
  output
end