Sha256: bf409d193326a536fcfe32a6c8fa543433f8003add207b05202afde7658fbc6f

Contents?: true

Size: 747 Bytes

Versions: 1

Compression:

Stored size: 747 Bytes

Contents

class Toxiproxy
  class ToxicCollection
    extend Forwardable

    attr_accessor :toxics
    attr_reader :proxy

    def_delegators :@toxics, :<<, :find

    def initialize(proxy)
      @proxy  = proxy
      @toxics = []
    end

    def apply(&block)
      @toxics.each(&:enable)
      yield
    ensure
      @toxics.each(&:disable)
    end

    def upstream(toxic_name, attrs = {})
      toxics << Toxic.new(
        name: toxic_name,
        proxy: proxy,
        direction: :upstream,
        attrs: attrs
      )
      self
    end

    def downstream(toxic_name, attrs = {})
      toxics << Toxic.new(
        name: toxic_name,
        proxy: proxy,
        direction: :downstream,
        attrs: attrs
      )
      self
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
toxiproxy-0.0.2 lib/toxiproxy/toxic_collection.rb