lib/datadog/appsec/reactive/engine.rb in ddtrace-1.9.0 vs lib/datadog/appsec/reactive/engine.rb in ddtrace-1.10.0

- old
+ new

@@ -1,6 +1,6 @@ -# typed: ignore +# frozen_string_literal: true require_relative 'address_hash' require_relative 'subscriber' module Datadog @@ -8,24 +8,23 @@ module Reactive # Reactive Engine class Engine def initialize @data = {} - @subscribers = AddressHash.new { |h, k| h[k] = [] } # TODO: move to AddressHash initializer - @children = [] + @subscribers = AddressHash.new end def subscribe(*addresses, &block) - @subscribers[addresses.freeze] << Subscriber.new(&block).freeze # TODO: move freeze to Subscriber + @subscribers[addresses.freeze] << Subscriber.new(&block) end - def publish(address, data) + def publish(address, value) # check if someone has address subscribed if @subscribers.addresses.include?(address) - # someone will be interested, set data - @data[address] = data + # someone will be interested, set value + @data[address] = value # find candidates i.e address groups that contain the just posted address @subscribers.with(address).each do |addresses| # find targets to the address group containing the posted address subscribers = @subscribers[addresses] @@ -36,9 +35,13 @@ subscribers.each { |s| s.call(*hash.values) } end end end end + + private + + attr_reader :subscribers, :data end end end end