Sha256: ed328e8978b8a6fbc908bf8a79f301a94b6659e87a1ccd3891fd38c5d61a73bf

Contents?: true

Size: 1.34 KB

Versions: 24

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

module Datadog
  module Core
    module Remote
      # Repository update dispatcher
      class Dispatcher
        attr_reader :receivers

        def initialize
          @receivers = []
        end

        def dispatch(changes, repository)
          receivers.each do |receiver|
            matching_changes = changes.select { |c| receiver.match?(c.path) }

            receiver.call(repository, matching_changes) if matching_changes.any?
          end
        end

        # Store Matcher and block to be executed on a match
        class Receiver
          def initialize(matcher, &block)
            @block = block
            @matcher = matcher
          end

          def match?(path)
            @matcher.match?(path)
          end

          def call(repository, changes)
            @block.call(repository, changes)
          end
        end

        # Matcher checks if the path matches
        class Matcher
          def initialize(&block)
            @block = block
          end

          def match?(path)
            @block.call(path)
          end

          # Matches on the produc's path
          class Product < Matcher
            def initialize(products)
              block = ->(path) { products.include?(path.product) }
              super(&block)
            end
          end
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
ddtrace-1.23.3 lib/datadog/core/remote/dispatcher.rb
ddtrace-1.23.2 lib/datadog/core/remote/dispatcher.rb
ddtrace-1.23.1 lib/datadog/core/remote/dispatcher.rb
datadog-2.0.0.beta2 lib/datadog/core/remote/dispatcher.rb
ddtrace-1.22.0 lib/datadog/core/remote/dispatcher.rb
datadog-2.0.0.beta1 lib/datadog/core/remote/dispatcher.rb
ddtrace-1.21.1 lib/datadog/core/remote/dispatcher.rb
ddtrace-1.21.0 lib/datadog/core/remote/dispatcher.rb
ddtrace-1.20.0 lib/datadog/core/remote/dispatcher.rb
ddtrace-1.19.0 lib/datadog/core/remote/dispatcher.rb
ddtrace-1.18.0 lib/datadog/core/remote/dispatcher.rb
ddtrace-1.17.0 lib/datadog/core/remote/dispatcher.rb
ddtrace-1.16.2 lib/datadog/core/remote/dispatcher.rb
ddtrace-1.16.1 lib/datadog/core/remote/dispatcher.rb
ddtrace-1.16.0 lib/datadog/core/remote/dispatcher.rb
ddtrace-1.15.0 lib/datadog/core/remote/dispatcher.rb
ddtrace-1.14.0 lib/datadog/core/remote/dispatcher.rb
ddtrace-1.13.1 lib/datadog/core/remote/dispatcher.rb
ddtrace-1.13.0 lib/datadog/core/remote/dispatcher.rb
ddtrace-1.12.1 lib/datadog/core/remote/dispatcher.rb