Class: RailsAiBridge::Services::ConfigurationService
- Inherits:
-
RailsAiBridge::Service
- Object
- RailsAiBridge::Service
- RailsAiBridge::Services::ConfigurationService
- Defined in:
- lib/rails_ai_bridge/services/configuration_service.rb
Overview
Application service for reading and updating the gem's global configuration.
Serializes access to RailsAiBridge.configuration with a class-level mutex so concurrent threads cannot interleave reads and in-place updates performed in the optional block. Standard errors are captured and returned as a failed RailsAiBridge::Service::Result rather than raised.
Constant Summary collapse
- MUTEX =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Mutex.new
Class Method Summary collapse
-
.call {|config| ... } ⇒ RailsAiBridge::Service::Result
Class-level entry point; instantiates the service and delegates to #call.
Instance Method Summary collapse
-
#call {|config| ... } ⇒ RailsAiBridge::Service::Result
Returns the current configuration, optionally yielding it for in-place updates.
Methods inherited from RailsAiBridge::Service
Constructor Details
This class inherits a constructor from RailsAiBridge::Service
Class Method Details
.call {|config| ... } ⇒ RailsAiBridge::Service::Result
Class-level entry point; instantiates the service and delegates to #call.
35 36 37 |
# File 'lib/rails_ai_bridge/services/configuration_service.rb', line 35 def self.call(&) new.call(&) end |
Instance Method Details
#call {|config| ... } ⇒ RailsAiBridge::Service::Result
Returns the current configuration, optionally yielding it for in-place updates.
The configuration read and optional block run inside MUTEX so the sequence is atomic with respect to other calls to this service in the same process.
48 49 50 51 52 53 54 55 56 |
# File 'lib/rails_ai_bridge/services/configuration_service.rb', line 48 def call(&block) MUTEX.synchronize do config = RailsAiBridge.configuration block&.call(config) Service::Result.new(true, data: config) end rescue StandardError => error Service::Result.new(false, errors: [error.]) end |