Sha256: a7bb6f22db669a9ea45460bb47d8db0a9e48db7e2d8514ebc4018e23979c11fa

Contents?: true

Size: 943 Bytes

Versions: 23

Compression:

Stored size: 943 Bytes

Contents

module Flipper
  module Instrumenters
    # Instrumentor that is useful for tests as it stores each of the events that
    # are instrumented.
    class Memory
      Event = Struct.new(:name, :payload, :result)

      attr_reader :events

      def initialize
        @events = []
      end

      def instrument(name, payload = {})
        # Copy the payload to guard against later modifications to it, and to
        # ensure that all instrumentation code uses the payload passed to the
        # block rather than the one passed to #instrument.
        payload = payload.dup

        result = (yield payload if block_given?)
        @events << Event.new(name, payload, result)
        result
      end

      def events_by_name(name)
        @events.select { |event| event.name == name }
      end

      def event_by_name(name)
        events_by_name(name).first
      end

      def reset
        @events = []
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
flipper-0.22.2 lib/flipper/instrumenters/memory.rb
flipper-0.22.1 lib/flipper/instrumenters/memory.rb
flipper-0.22.0 lib/flipper/instrumenters/memory.rb
flipper-0.21.0 lib/flipper/instrumenters/memory.rb
flipper-0.21.0.rc2 lib/flipper/instrumenters/memory.rb
flipper-0.21.0.rc1 lib/flipper/instrumenters/memory.rb
flipper-0.20.4 lib/flipper/instrumenters/memory.rb
flipper-0.20.3 lib/flipper/instrumenters/memory.rb
flipper-0.20.2 lib/flipper/instrumenters/memory.rb
flipper-0.20.1 lib/flipper/instrumenters/memory.rb
flipper-0.20.0 lib/flipper/instrumenters/memory.rb
flipper-0.20.0.beta3 lib/flipper/instrumenters/memory.rb
flipper-0.20.0.beta2 lib/flipper/instrumenters/memory.rb
flipper-0.20.0.beta1 lib/flipper/instrumenters/memory.rb
flipper-0.19.1 lib/flipper/instrumenters/memory.rb
flipper-0.19.0 lib/flipper/instrumenters/memory.rb
flipper-0.18.0 lib/flipper/instrumenters/memory.rb
flipper-0.17.2 lib/flipper/instrumenters/memory.rb
flipper-0.17.1 lib/flipper/instrumenters/memory.rb
flipper-0.16.2 lib/flipper/instrumenters/memory.rb