Module: LogStash::Inputs::AkamaiSiem::MiddlewareRegistry

Included in:
Exception, Request
Defined in:
lib/logstash/inputs/akamai_siem/middleware_registry.rb

Instance Method Summary collapse

Instance Method Details

#lookup_middleware(key) ⇒ Class

Lookup middleware class with a registered Symbol shortcut.

Examples:


module Faraday
  class Whatever < Middleware
    register_middleware(foo: Whatever)
  end
end

Faraday::Middleware.lookup_middleware(:foo)
# => Faraday::Whatever

Parameters:

  • key (Symbol)

    key for the registered middleware.

Returns:

  • (Class)

    a middleware Class.

Raises:

  • (Faraday::Error)

    if given key is not registered



54
55
56
57
# File 'lib/logstash/inputs/akamai_siem/middleware_registry.rb', line 54

def lookup_middleware(key)
  load_middleware(key) ||
    raise(Faraday::Error, "#{key.inspect} is not registered on #{self}")
end

#register_middleware(**mappings) ⇒ void

This method returns an undefined value.

Register middleware class(es) on the current module.

Examples:

Lookup by a constant


module Faraday
  class Whatever < Middleware
    # Middleware looked up by :foo returns Faraday::Whatever::Foo.
    register_middleware(foo: Whatever)
  end
end

Parameters:

  • mappings (Hash)

    Middleware mappings from a lookup symbol to a middleware class.



25
26
27
28
29
# File 'lib/logstash/inputs/akamai_siem/middleware_registry.rb', line 25

def register_middleware(**mappings)
  middleware_mutex do
    registered_middleware.update(mappings)
  end
end

#registered_middlewareObject

Adds the ability for other modules to register and lookup middleware classes.



8
9
10
# File 'lib/logstash/inputs/akamai_siem/middleware_registry.rb', line 8

def registered_middleware
  @registered_middleware ||= {}
end

#unregister_middleware(key) ⇒ Object

Unregister a previously registered middleware class.

Parameters:

  • key (Symbol)

    key for the registered middleware.



34
35
36
# File 'lib/logstash/inputs/akamai_siem/middleware_registry.rb', line 34

def unregister_middleware(key)
  registered_middleware.delete(key)
end