Class: FlowChat::Factory
- Inherits:
-
Object
- Object
- FlowChat::Factory
- Defined in:
- lib/flow_chat/factory.rb
Overview
Factory provides centralized processor configuration for consistent setup across webhook and background contexts.
Example:
# In config/initializers/flow_chat.rb
FlowChat::Factory.register :whatsapp do |controller|
processor = FlowChat::Processor.new(controller) do |config|
config.use_gateway FlowChat::Whatsapp::Gateway::CloudApi
config.use_session_store FlowChat::Session::CacheSessionStore
config.use_session_config(boundaries: [:flow])
config.use_async(WhatsAppFlowJob)
end
processor.run(WhatsAppFlow, :start)
end
# In webhook controller
FlowChat::Factory.execute(:whatsapp, controller: self)
# In background job
FlowChat::Factory.execute(:whatsapp, controller: controller)
Defined Under Namespace
Classes: FactoryNotFoundError
Class Method Summary collapse
-
.clear! ⇒ void
Clear all registered factories (primarily for testing).
-
.execute(name, controller:) ⇒ void
Execute a registered factory.
-
.register(name, &block) ⇒ void
Register a processor factory with a given name.
-
.registered?(name) ⇒ Boolean
Check if a factory is registered.
-
.registered_factories ⇒ Array<Symbol>
Get all registered factory names.
Class Method Details
.clear! ⇒ void
This method returns an undefined value.
Clear all registered factories (primarily for testing)
79 80 81 82 |
# File 'lib/flow_chat/factory.rb', line 79 def clear! FlowChat.logger.debug { "Factory: Clearing all registered factories" } factories.clear end |
.execute(name, controller:) ⇒ void
This method returns an undefined value.
Execute a registered factory
53 54 55 56 57 58 59 |
# File 'lib/flow_chat/factory.rb', line 53 def execute(name, controller:) factory = factories[name] raise FactoryNotFoundError, "Factory '#{name}' not registered" unless factory FlowChat.logger.debug { "Factory: Executing factory '#{name}'" } factory.call(controller) end |
.register(name, &block) ⇒ void
This method returns an undefined value.
Register a processor factory with a given name
39 40 41 42 |
# File 'lib/flow_chat/factory.rb', line 39 def register(name, &block) FlowChat.logger.debug { "Factory: Registering factory '#{name}'" } factories[name] = block end |
.registered?(name) ⇒ Boolean
Check if a factory is registered
65 66 67 |
# File 'lib/flow_chat/factory.rb', line 65 def registered?(name) factories.key?(name) end |
.registered_factories ⇒ Array<Symbol>
Get all registered factory names
72 73 74 |
# File 'lib/flow_chat/factory.rb', line 72 def registered_factories factories.keys end |