Class: FactoryManager::Generator
- Inherits:
-
Object
- Object
- FactoryManager::Generator
- Defined in:
- lib/factory_manager/generator.rb
Overview
The factory manager generator.
Instance Method Summary collapse
-
#generate { ... } ⇒ OpenStruct
Generates the factory.
-
#initialize(strategy:) ⇒ Generator
constructor
Initializes a new factory generator.
Constructor Details
#initialize(strategy:) ⇒ Generator
Initializes a new factory generator.
7 8 9 10 11 |
# File 'lib/factory_manager/generator.rb', line 7 def initialize(strategy:) @associations = {} @results = {} @strategy = strategy end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arguments, &block) ⇒ ActiveRecord::Base (private)
Attempts to generate a factory record for the missing method.
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/factory_manager/generator.rb', line 117 def method_missing(method, *arguments, &block) super unless respond_to_missing?(method) if _sequence?(method, arguments.first) _generate_sequence(*arguments) else record = _generate_factory(method, *arguments) _add_association(record, name: method) do generate(&block) if block end end end |
Instance Method Details
#generate { ... } ⇒ OpenStruct
Generates the factory.
17 18 19 20 21 |
# File 'lib/factory_manager/generator.rb', line 17 def generate(&block) OpenStruct.new.tap do |locals| # rubocop:disable Style/OpenStructUse instance_exec(locals, &block) end end |