Sha256: 92d78583a2a3954fda67d9a205269a6def399acc6183d3ceb7d92b5be1ff6e54

Contents?: true

Size: 791 Bytes

Versions: 6

Compression:

Stored size: 791 Bytes

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

module FlakyProxy
  class RuleSet
    class Builder
      attr_reader :rules

      def initialize(ruleset, &blk)
        @ruleset = ruleset
        @rules = []
      end

      def match(criteria, &blk)
        @ruleset.rules << Rule.new(criteria, &blk)
      end
    end

    def self.build(text=nil, &blk)
      ruleset = self.new
      Builder.new(ruleset).instance_eval(text, &blk)
      ruleset
    end

    attr_accessor :rules

    def initialize
      @rules = []
      @default_rule = Rule.new { pass }
    end

    def match(request)
      @rules.detect { |rule| rule.match?(request) } || @default_rule
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
newrelic_rpm-3.7.2.195 test/flaky_proxy/lib/flaky_proxy/rule_set.rb
newrelic_rpm-3.7.2.192 test/flaky_proxy/lib/flaky_proxy/rule_set.rb
newrelic_rpm-3.7.2.190.beta test/flaky_proxy/lib/flaky_proxy/rule_set.rb
newrelic_rpm-3.7.1.188 test/flaky_proxy/lib/flaky_proxy/rule_set.rb
newrelic_rpm-3.7.1.182 test/flaky_proxy/lib/flaky_proxy/rule_set.rb
newrelic_rpm-3.7.1.180 test/flaky_proxy/lib/flaky_proxy/rule_set.rb