Class: FactoryBurgers::Builder
- Inherits:
-
Object
- Object
- FactoryBurgers::Builder
- Defined in:
- lib/factory_burgers/builder.rb
Overview
Build resources from specified factories, traits, and attributes
Instance Attribute Summary collapse
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
Instance Method Summary collapse
-
#build(factory, traits, attributes, as: nil) ⇒ Object
TODO: clean up method signature.
-
#initialize(owner = nil) ⇒ Builder
constructor
‘owner` is an optional resource that we can attach new resources to E.g.
Constructor Details
#initialize(owner = nil) ⇒ Builder
‘owner` is an optional resource that we can attach new resources to E.g. a `User` for whom we wish to build a `Post`.
8 9 10 |
# File 'lib/factory_burgers/builder.rb', line 8 def initialize(owner = nil) @owner = owner end |
Instance Attribute Details
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
4 5 6 |
# File 'lib/factory_burgers/builder.rb', line 4 def owner @owner end |
Instance Method Details
#build(factory, traits, attributes, as: nil) ⇒ Object
TODO: clean up method signature
13 14 15 16 17 18 19 20 |
# File 'lib/factory_burgers/builder.rb', line 13 def build(factory, traits, attributes, as: nil) # rubocop:disable Naming/MethodParameterName; as is a good name here resource = insistently do FactoryBot.create(factory, *traits, attributes) end update_assocation_to_owner(as, resource) if owner && as return resource end |