Module: NetworkResiliency::Adapter::Rails

Extended by:
Rails
Included in:
Rails
Defined in:
lib/network_resiliency/adapter/rails.rb

Defined Under Namespace

Classes: Middleware

Instance Method Summary collapse

Instance Method Details

#patch(instance = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/network_resiliency/adapter/rails.rb', line 9

def patch(instance = nil)
  instance ||= ::Rails.application

  unless instance.is_a?(::Rails::Application)
    raise ArgumentError, "expected Rails::Application instance, found: #{instance}"
  end

  return if patched?(instance)

  instance.config.middleware.use Middleware
end

#patched?(instance = nil) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
# File 'lib/network_resiliency/adapter/rails.rb', line 21

def patched?(instance = nil)
  instance ||= ::Rails.application

  return false unless instance.initialized?

  instance.config.middleware.include?(Middleware)
end