Class: Datadog::AppSec::Instrumentation::Gateway
- Inherits:
-
Object
- Object
- Datadog::AppSec::Instrumentation::Gateway
- Defined in:
- lib/datadog/appsec/instrumentation/gateway.rb,
lib/datadog/appsec/instrumentation/gateway/argument.rb
Overview
Instrumentation gateway implementation
Defined Under Namespace
Instance Method Summary collapse
-
#initialize ⇒ Gateway
constructor
A new instance of Gateway.
- #push(name, env, &block) ⇒ Object
- #watch(name, key, &block) ⇒ Object
Constructor Details
#initialize ⇒ Gateway
Returns a new instance of Gateway.
25 26 27 |
# File 'lib/datadog/appsec/instrumentation/gateway.rb', line 25 def initialize @middlewares = Hash.new { |h, k| h[k] = [] } end |
Instance Method Details
#push(name, env, &block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/datadog/appsec/instrumentation/gateway.rb', line 29 def push(name, env, &block) block ||= -> {} middlewares_for_name = middlewares[name] return [block.call, nil] if middlewares_for_name.empty? wrapped = lambda do |_env| [block.call, nil] end # TODO: handle exceptions, except for wrapped stack = middlewares_for_name.reverse.reduce(wrapped) do |next_, middleware| lambda do |env_| middleware.call(next_, env_) end end stack.call(env) end |
#watch(name, key, &block) ⇒ Object
50 51 52 |
# File 'lib/datadog/appsec/instrumentation/gateway.rb', line 50 def watch(name, key, &block) @middlewares[name] << Middleware.new(key, &block) unless middlewares[name].any? { |m| m.key == key } end |