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,
  :get_multi,
  :get_all,
  :enable,
  :disable,
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Flipper::Adapter

#default_config, #import, included

Constructor Details

#initialize(adapter, operations = nil) ⇒ OperationLogger

Public



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

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.



36
37
38
# File 'lib/flipper/adapters/operation_logger.rb', line 36

def name
  @name
end

#operationsObject (readonly)

Internal: An array of the operations that have happened.



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

def operations
  @operations
end

Instance Method Details

#add(feature) ⇒ Object

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



53
54
55
56
# File 'lib/flipper/adapters/operation_logger.rb', line 53

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

#clear(feature) ⇒ Object

Public: Clears all the gate values for a feature.



66
67
68
69
# File 'lib/flipper/adapters/operation_logger.rb', line 66

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.



102
103
104
# File 'lib/flipper/adapters/operation_logger.rb', line 102

def count(type)
  type(type).size
end

#disable(feature, gate, thing) ⇒ Object

Public



96
97
98
99
# File 'lib/flipper/adapters/operation_logger.rb', line 96

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

#enable(feature, gate, thing) ⇒ Object

Public



90
91
92
93
# File 'lib/flipper/adapters/operation_logger.rb', line 90

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.



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

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

#get(feature) ⇒ Object

Public



72
73
74
75
# File 'lib/flipper/adapters/operation_logger.rb', line 72

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

#get_allObject

Public



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

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

#get_multi(features) ⇒ Object

Public



78
79
80
81
# File 'lib/flipper/adapters/operation_logger.rb', line 78

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

#last(type) ⇒ Object

Public: Get the last operation of a certain type.



112
113
114
# File 'lib/flipper/adapters/operation_logger.rb', line 112

def last(type)
  @operations.reverse.find { |operation| operation.type == type }
end

#remove(feature) ⇒ Object

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



60
61
62
63
# File 'lib/flipper/adapters/operation_logger.rb', line 60

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

#resetObject

Public: Resets the operation log to empty



117
118
119
# File 'lib/flipper/adapters/operation_logger.rb', line 117

def reset
  @operations.clear
end

#type(type) ⇒ Object

Public: Get all operations of a certain type.



107
108
109
# File 'lib/flipper/adapters/operation_logger.rb', line 107

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