diff --git a/lib/circuitbox.rb b/lib/circuitbox.rb index da85aca..06cc7df 100644 --- a/lib/circuitbox.rb +++ b/lib/circuitbox.rb @@ -11,6 +11,28 @@ class Circuitbox extend Configuration class << self + # @overload circuit(service_name, options = {}) + # Returns a Circuitbox::CircuitBreaker for the given service_name + # + # @param service_name [String, Symbol] Name of the service + # Mixing Symbols/Strings for the same service (:test/'test') will result in + # multiple circuits being created that point to the same service. + # @param options [Hash] Options for the circuit (See Circuitbox::CircuitBreaker#initialize options) + # Any configuration options should always be passed when calling this method. + # @return [Circuitbox::CircuitBreaker] CircuitBreaker for the given service_name + # + # @overload circuit(service_name, options = {}, &block) + # Runs the circuit with the given block + # The circuit's run method is called with `exception` set to false + # + # @param service_name [String, Symbol] Name of the service + # Mixing Symbols/Strings for the same service (:test/'test') will result in + # multiple circuits being created that point to the same service. + # @param options [Hash] Options for the circuit (See Circuitbox::CircuitBreaker#initialize options) + # Any configuration options should always be passed when calling this method. + # + # @return [Object] The result of the block + # @return [nil] If the circuit is open def circuit(service_name, options, &block) circuit = find_or_create_circuit_breaker(service_name, options) diff --git a/lib/circuitbox/configuration.rb b/lib/circuitbox/configuration.rb index c9de597..fa79850 100644 --- a/lib/circuitbox/configuration.rb +++ b/lib/circuitbox/configuration.rb @@ -19,16 +19,30 @@ def self.extended(base) end end + # Configure Circuitbox's defaults + # After configuring the cached circuits are cleared + # + # @yieldparam [Circuitbox::Configuration] Circuitbox configuration + # def configure yield self clear_cached_circuits! nil end + # Circuit store used by circuits that are not configured with a specific circuit store + # Defaults to Circuitbox::MemoryStore + # + # @return [Circuitbox::MemoryStore, Moneta] Circuit store def default_circuit_store @default_circuit_store ||= MemoryStore.new end + # Notifier used by circuits that are not configured with a specific notifier. + # If ActiveSupport::Notifications is defined it defaults to Circuitbox::Notifier::ActiveSupport + # Otherwise it defaults to Circuitbox::Notifier::Null + # + # @return [Circuitbox::Notifier::ActiveSupport, Circuitbox::Notifier::Null] Notifier def default_notifier @default_notifier ||= if defined?(ActiveSupport::Notifications) Notifier::ActiveSupport.new