Class: Flipper::Adapters::OperationLogger

Inherits:
Decorator show all
Defined in:
lib/flipper/adapters/operation_logger.rb

Overview

Public: Adapter that wraps another adapter and stores the operations.

Useful in tests to verify calls and such. Never use outside of testing.

Defined Under Namespace

Classes: Operation

Constant Summary collapse

OperationTypes =
[
  :features,
  :add,
  :remove,
  :clear,
  :get,
  :enable,
  :disable,
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter, operations = nil) ⇒ OperationLogger

Public



25
26
27
28
# File 'lib/flipper/adapters/operation_logger.rb', line 25

def initialize(adapter, operations = nil)
  super(adapter)
  @operations = operations || []
end

Instance Attribute Details

#operationsObject (readonly)

Internal: An array of the operations that have happened.



22
23
24
# File 'lib/flipper/adapters/operation_logger.rb', line 22

def operations
  @operations
end

Instance Method Details

#count(type) ⇒ Object

Public: Count the number of times a certain operation happened.



41
42
43
# File 'lib/flipper/adapters/operation_logger.rb', line 41

def count(type)
  @operations.select { |operation| operation.type == type }.size
end

#resetObject

Public: Resets the operation log to empty



46
47
48
# File 'lib/flipper/adapters/operation_logger.rb', line 46

def reset
  @operations.clear
end