lib/circuitbox/excon_middleware.rb in circuitbox-2.0.0.pre3 vs lib/circuitbox/excon_middleware.rb in circuitbox-2.0.0.pre4

- old
+ new

@@ -1,16 +1,18 @@ +# frozen_string_literal: true + require 'excon' require 'circuitbox' class Circuitbox class ExconMiddleware < Excon::Middleware::Base class RequestFailed < StandardError; end DEFAULT_EXCEPTIONS = [ Excon::Errors::Timeout, RequestFailed - ] + ].freeze class NullResponse < Excon::Response def initialize(response, exception) @original_response = response @original_exception = exception @@ -24,21 +26,21 @@ attr_reader :opts def initialize(stack, opts = {}) @stack = stack - default_options = { open_circuit: lambda { |response| response[:status] >= 400 } } + default_options = { open_circuit: ->(response) { response[:status] >= 400 } } @opts = default_options.merge(opts) super(stack) end def error_call(datum) circuit(datum).run do raise RequestFailed end - rescue Circuitbox::Error => exception - circuit_open_value(datum, datum[:response], exception) + rescue Circuitbox::Error => e + circuit_open_value(datum, datum[:response], e) end def request_call(datum) circuit(datum).run do @stack.request_call(datum) @@ -48,12 +50,12 @@ def response_call(datum) circuit(datum).run do raise RequestFailed if open_circuit?(datum[:response]) end @stack.response_call(datum) - rescue Circuitbox::Error => exception - circuit_open_value(datum, datum[:response], exception) + rescue Circuitbox::Error => e + circuit_open_value(datum, datum[:response], e) end def identifier @identifier ||= opts.fetch(:identifier, ->(env) { env[:host] }) end @@ -91,12 +93,12 @@ end def default_value @default_value ||= begin default = opts.fetch(:default_value) do - lambda { |response, exception| NullResponse.new(response, exception) } + ->(response, exception) { NullResponse.new(response, exception) } end - default.respond_to?(:call) ? default : lambda { |*| default } + default.respond_to?(:call) ? default : ->(*) { default } end end end end