Class: FaradayMiddleware::CircuitBreaker::OptionSet

Inherits:
Object
  • Object
show all
Defined in:
lib/faraday_middleware/circuit_breaker/option_set.rb

Constant Summary collapse

VALID_OPTIONS =
%w(timeout threshold fallback notifiers data_store error_handler cache_key_generator)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ OptionSet

Returns a new instance of OptionSet.



13
14
15
16
17
18
19
20
21
# File 'lib/faraday_middleware/circuit_breaker/option_set.rb', line 13

def initialize(options = {})
  @timeout    = options[:timeout] || 60.0
  @threshold  = options[:threshold] || 3
  @fallback   = options[:fallback] || proc { Faraday::Response.new(status: 503, response_headers: {}) }
  @notifiers  = options[:notifiers] || {}
  @data_store = options[:data_store] || proc { Stoplight::Light.default_data_store }
  @error_handler = options[:error_handler] || Stoplight::Default::ERROR_HANDLER
  @cache_key_generator = options[:cache_key_generator] || ->(url) { URI.join(url, '/').to_s }
end

Instance Attribute Details

#cache_key_generatorObject

Returns the value of attribute cache_key_generator.



11
12
13
# File 'lib/faraday_middleware/circuit_breaker/option_set.rb', line 11

def cache_key_generator
  @cache_key_generator
end

#data_storeObject

Returns the value of attribute data_store.



11
12
13
# File 'lib/faraday_middleware/circuit_breaker/option_set.rb', line 11

def data_store
  @data_store
end

#error_handlerObject

Returns the value of attribute error_handler.



11
12
13
# File 'lib/faraday_middleware/circuit_breaker/option_set.rb', line 11

def error_handler
  @error_handler
end

#fallbackObject

Returns the value of attribute fallback.



11
12
13
# File 'lib/faraday_middleware/circuit_breaker/option_set.rb', line 11

def fallback
  @fallback
end

#notifiersObject

Returns the value of attribute notifiers.



11
12
13
# File 'lib/faraday_middleware/circuit_breaker/option_set.rb', line 11

def notifiers
  @notifiers
end

#thresholdObject

Returns the value of attribute threshold.



11
12
13
# File 'lib/faraday_middleware/circuit_breaker/option_set.rb', line 11

def threshold
  @threshold
end

#timeoutObject

Returns the value of attribute timeout.



11
12
13
# File 'lib/faraday_middleware/circuit_breaker/option_set.rb', line 11

def timeout
  @timeout
end

Class Method Details

.validate!(options) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/faraday_middleware/circuit_breaker/option_set.rb', line 23

def self.validate!(options)
  options.each_key do |key|
    unless VALID_OPTIONS.include?(key.to_s)
      fail ArgumentError.new("Unknown option: #{key}. Valid options are :#{VALID_OPTIONS.join(', ')}")
    end
  end
end