Class: CucumberFactory::BuildStrategy
- Inherits:
-
Object
- Object
- CucumberFactory::BuildStrategy
- Defined in:
- lib/cucumber_factory/build_strategy.rb
Overview
wraps machinist / factory_bot / ruby object logic
Instance Attribute Summary collapse
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
Class Method Summary collapse
- .class_from_factory(model_prose) ⇒ Object
- .from_prose(model_prose, variant_prose) ⇒ Object
- .parse_model_class(model_prose) ⇒ Object
Instance Method Summary collapse
- #create_record(attributes) ⇒ Object
-
#initialize(model_class, &block) ⇒ BuildStrategy
constructor
A new instance of BuildStrategy.
Constructor Details
#initialize(model_class, &block) ⇒ BuildStrategy
Returns a new instance of BuildStrategy.
156 157 158 159 |
# File 'lib/cucumber_factory/build_strategy.rb', line 156 def initialize(model_class, &block) @model_class = model_class @create_proc = block end |
Instance Attribute Details
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class.
154 155 156 |
# File 'lib/cucumber_factory/build_strategy.rb', line 154 def model_class @model_class end |
Class Method Details
.class_from_factory(model_prose) ⇒ Object
25 26 27 28 29 |
# File 'lib/cucumber_factory/build_strategy.rb', line 25 def class_from_factory(model_prose) if (factory = factory_bot_factory(model_prose, [])) factory.build_class end end |
.from_prose(model_prose, variant_prose) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/cucumber_factory/build_strategy.rb', line 9 def from_prose(model_prose, variant_prose) variants = variants_from_prose(variant_prose) factory = factory_bot_factory(model_prose, variants) if factory factory.compile # Required to load inherited traits! strategy = factory_bot_strategy(factory, model_prose, variants) transient_attributes = factory_bot_transient_attributes(factory, variants) else strategy = alternative_strategy(model_prose, variants) transient_attributes = [] end [strategy, transient_attributes] end |
.parse_model_class(model_prose) ⇒ Object
31 32 33 |
# File 'lib/cucumber_factory/build_strategy.rb', line 31 def parse_model_class(model_prose) underscored_model_name(model_prose).camelize.constantize end |
Instance Method Details
#create_record(attributes) ⇒ Object
161 162 163 |
# File 'lib/cucumber_factory/build_strategy.rb', line 161 def create_record(attributes) @create_proc.call(attributes) end |