Class: Flipper::Adapters::OperationLogger

Inherits:
SimpleDelegator
  • Object
show all
Includes:
Flipper::Adapter
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



30
31
32
33
34
35
# File 'lib/flipper/adapters/operation_logger.rb', line 30

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

Instance Attribute Details

#nameObject (readonly)

Internal: The name of the adapter.



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

def name
  @name
end

#operationsObject (readonly)

Internal: An array of the operations that have happened.



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

def operations
  @operations
end

Instance Method Details

#add(feature) ⇒ Object

Public: Adds a feature to the set of known features.



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

def add(feature)
  @operations << Operation.new(:add, [feature])
  @adapter.add(feature)
end

#clear(feature) ⇒ Object

Public: Clears all the gate values for a feature.



57
58
59
60
# File 'lib/flipper/adapters/operation_logger.rb', line 57

def clear(feature)
  @operations << Operation.new(:clear, [feature])
  @adapter.clear(feature)
end

#count(type) ⇒ Object

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



81
82
83
# File 'lib/flipper/adapters/operation_logger.rb', line 81

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

#disable(feature, gate, thing) ⇒ Object

Public



75
76
77
78
# File 'lib/flipper/adapters/operation_logger.rb', line 75

def disable(feature, gate, thing)
  @operations << Operation.new(:disable, [feature, gate, thing])
  @adapter.disable(feature, gate, thing)
end

#enable(feature, gate, thing) ⇒ Object

Public



69
70
71
72
# File 'lib/flipper/adapters/operation_logger.rb', line 69

def enable(feature, gate, thing)
  @operations << Operation.new(:enable, [feature, gate, thing])
  @adapter.enable(feature, gate, thing)
end

#featuresObject

Public: The set of known features.



38
39
40
41
# File 'lib/flipper/adapters/operation_logger.rb', line 38

def features
  @operations << Operation.new(:features, [])
  @adapter.features
end

#get(feature) ⇒ Object

Public



63
64
65
66
# File 'lib/flipper/adapters/operation_logger.rb', line 63

def get(feature)
  @operations << Operation.new(:get, [feature])
  @adapter.get(feature)
end

#remove(feature) ⇒ Object

Public: Removes a feature from the set of known features and clears all the values for the feature.



51
52
53
54
# File 'lib/flipper/adapters/operation_logger.rb', line 51

def remove(feature)
  @operations << Operation.new(:remove, [feature])
  @adapter.remove(feature)
end

#resetObject

Public: Resets the operation log to empty



86
87
88
# File 'lib/flipper/adapters/operation_logger.rb', line 86

def reset
  @operations.clear
end