Skip to content

Commit

Permalink
Add missing code documentation to circuitbox.rb and circuitbox/config…
Browse files Browse the repository at this point in the history
…uration.rb
  • Loading branch information
matthewshafer committed May 4, 2023
1 parent 132740b commit 89c2b95
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/circuitbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
14 changes: 14 additions & 0 deletions lib/circuitbox/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 89c2b95

Please sign in to comment.