Class: Flipper::Instrumenters::Memory
- Inherits:
-
Object
- Object
- Flipper::Instrumenters::Memory
- Defined in:
- lib/flipper/instrumenters/memory.rb
Overview
Instrumentor that is useful for tests as it stores each of the events that are instrumented.
Defined Under Namespace
Classes: Event
Instance Attribute Summary collapse
-
#events ⇒ Object
readonly
Returns the value of attribute events.
Instance Method Summary collapse
- #event_by_name(name) ⇒ Object
- #events_by_name(name) ⇒ Object
-
#initialize ⇒ Memory
constructor
A new instance of Memory.
- #instrument(name, payload = {}) ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize ⇒ Memory
Returns a new instance of Memory.
10 11 12 |
# File 'lib/flipper/instrumenters/memory.rb', line 10 def initialize @events = [] end |
Instance Attribute Details
#events ⇒ Object (readonly)
Returns the value of attribute events.
8 9 10 |
# File 'lib/flipper/instrumenters/memory.rb', line 8 def events @events end |
Instance Method Details
#event_by_name(name) ⇒ Object
33 34 35 |
# File 'lib/flipper/instrumenters/memory.rb', line 33 def event_by_name(name) events_by_name(name).first end |
#events_by_name(name) ⇒ Object
29 30 31 |
# File 'lib/flipper/instrumenters/memory.rb', line 29 def events_by_name(name) @events.select { |event| event.name == name } end |
#instrument(name, payload = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/flipper/instrumenters/memory.rb', line 14 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? rescue Exception => e payload[:exception] = [e.class.name, e.] payload[:exception_object] = e raise e ensure @events << Event.new(name, payload, result) end |
#reset ⇒ Object
37 38 39 |
# File 'lib/flipper/instrumenters/memory.rb', line 37 def reset @events = [] end |