Class: RailsAi::Performance::LazyProvider
- Inherits:
-
Object
- Object
- RailsAi::Performance::LazyProvider
- Defined in:
- lib/rails_ai/performance.rb
Overview
Lazy loading for providers
Instance Method Summary collapse
-
#initialize(&provider_factory) ⇒ LazyProvider
constructor
A new instance of LazyProvider.
- #method_missing(method, *args, **kwargs, &block) ⇒ Object
- #respond_to_missing?(method, include_private = false) ⇒ Boolean
Constructor Details
#initialize(&provider_factory) ⇒ LazyProvider
Returns a new instance of LazyProvider.
210 211 212 213 214 |
# File 'lib/rails_ai/performance.rb', line 210 def initialize(&provider_factory) @provider_factory = provider_factory @provider = nil @mutex = Mutex.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, **kwargs, &block) ⇒ Object
216 217 218 219 220 221 |
# File 'lib/rails_ai/performance.rb', line 216 def method_missing(method, *args, **kwargs, &block) @mutex.synchronize do @provider ||= @provider_factory.call end @provider.public_send(method, *args, **kwargs, &block) end |
Instance Method Details
#respond_to_missing?(method, include_private = false) ⇒ Boolean
223 224 225 226 227 228 |
# File 'lib/rails_ai/performance.rb', line 223 def respond_to_missing?(method, include_private = false) @mutex.synchronize do @provider ||= @provider_factory.call end @provider.respond_to?(method, include_private) end |