Class: Breakers::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/breakers/client.rb

Overview

The client contains all of the data required to operate Breakers. Creating one and setting it as the global client allows the middleware to operate without parameters

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(redis_connection:, services:, plugins: nil, logger: nil) ⇒ Client

Create the Client object.



16
17
18
19
20
21
# File 'lib/breakers/client.rb', line 16

def initialize(redis_connection:, services:, plugins: nil, logger: nil)
  @redis_connection = redis_connection
  @services = Array(services)
  @plugins = Array(plugins)
  @logger = logger
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



8
9
10
# File 'lib/breakers/client.rb', line 8

def logger
  @logger
end

#pluginsObject (readonly)

Returns the value of attribute plugins.



6
7
8
# File 'lib/breakers/client.rb', line 6

def plugins
  @plugins
end

#redis_connectionObject (readonly)

Returns the value of attribute redis_connection.



7
8
9
# File 'lib/breakers/client.rb', line 7

def redis_connection
  @redis_connection
end

#servicesObject (readonly)

Returns the value of attribute services.



5
6
7
# File 'lib/breakers/client.rb', line 5

def services
  @services
end

Instance Method Details

#service_for_request(request_env:, service_name:) ⇒ Breakers::Service

Given a request environment, return the service that should handle it.



28
29
30
31
32
# File 'lib/breakers/client.rb', line 28

def service_for_request(request_env:, service_name:)
  @services.find do |service|
    service.handles_request?(request_env: request_env, service_name: service_name)
  end
end