Class: Makery::Factory
- Inherits:
-
Struct
- Object
- Struct
- Makery::Factory
- Defined in:
- lib/makery.rb
Overview
makes stuff
Instance Attribute Summary collapse
-
#count ⇒ Object
Returns the value of attribute count.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#traits_repository ⇒ Object
Returns the value of attribute traits_repository.
Instance Method Summary collapse
- #base(**attrs) ⇒ Object
- #call(*traits, **override) ⇒ Object
-
#initialize(*args) ⇒ Factory
constructor
A new instance of Factory.
- #instantiation_method(method = :new) ⇒ Object
- #trait(name, **attrs) ⇒ Object
- #trait_attrs(traits) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Factory
Returns a new instance of Factory.
20 21 22 23 24 |
# File 'lib/makery.rb', line 20 def initialize(*args) self.count = 1 self.traits_repository = {} super end |
Instance Attribute Details
#count ⇒ Object
Returns the value of attribute count.
19 20 21 |
# File 'lib/makery.rb', line 19 def count @count end |
#klass ⇒ Object
Returns the value of attribute klass
18 19 20 |
# File 'lib/makery.rb', line 18 def klass @klass end |
#traits_repository ⇒ Object
Returns the value of attribute traits_repository.
19 20 21 |
# File 'lib/makery.rb', line 19 def traits_repository @traits_repository end |
Instance Method Details
#base(**attrs) ⇒ Object
33 34 35 |
# File 'lib/makery.rb', line 33 def base(**attrs) @base ||= attrs end |
#call(*traits, **override) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/makery.rb', line 26 def call(*traits, **override) attrs = base.merge(**trait_attrs(traits), **override) Builder.call(attrs, klass, :new, count) ensure self.count = count + 1 end |
#instantiation_method(method = :new) ⇒ Object
37 38 39 |
# File 'lib/makery.rb', line 37 def instantiation_method(method = :new) @instantiation_method = method end |
#trait(name, **attrs) ⇒ Object
45 46 47 |
# File 'lib/makery.rb', line 45 def trait(name, **attrs) traits_repository[name] = attrs end |
#trait_attrs(traits) ⇒ Object
41 42 43 |
# File 'lib/makery.rb', line 41 def trait_attrs(traits) traits.map { |t| traits_repository[t] }.reduce({}, &:merge) end |