Class: Flipper::Adapters::OperationLogger
- Inherits:
-
Object
- Object
- Flipper::Adapters::OperationLogger
- 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
-
#name ⇒ Object
readonly
Internal: The name of the adapter.
-
#operations ⇒ Object
readonly
Internal: An array of the operations that have happened.
Instance Method Summary collapse
-
#add(feature) ⇒ Object
Public: Adds a feature to the set of known features.
-
#clear(feature) ⇒ Object
Public: Clears all the gate values for a feature.
-
#count(type) ⇒ Object
Public: Count the number of times a certain operation happened.
-
#disable(feature, gate, thing) ⇒ Object
Public.
-
#enable(feature, gate, thing) ⇒ Object
Public.
-
#features ⇒ Object
Public: The set of known features.
-
#get(feature) ⇒ Object
Public.
-
#initialize(adapter, operations = nil) ⇒ OperationLogger
constructor
Public.
-
#remove(feature) ⇒ Object
Public: Removes a feature from the set of known features and clears all the values for the feature.
-
#reset ⇒ Object
Public: Resets the operation log to empty.
Constructor Details
#initialize(adapter, operations = nil) ⇒ OperationLogger
Public
28 29 30 31 32 |
# File 'lib/flipper/adapters/operation_logger.rb', line 28 def initialize(adapter, operations = nil) @adapter = adapter @name = :operation_logger @operations = operations || [] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Internal: The name of the adapter.
25 26 27 |
# File 'lib/flipper/adapters/operation_logger.rb', line 25 def name @name end |
#operations ⇒ Object (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
#add(feature) ⇒ Object
Public: Adds a feature to the set of known features.
41 42 43 44 |
# File 'lib/flipper/adapters/operation_logger.rb', line 41 def add(feature) @operations << Operation.new(:add, [feature]) @adapter.add(feature) end |
#clear(feature) ⇒ Object
Public: Clears all the gate values for a feature.
54 55 56 57 |
# File 'lib/flipper/adapters/operation_logger.rb', line 54 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.
78 79 80 |
# File 'lib/flipper/adapters/operation_logger.rb', line 78 def count(type) @operations.select { |operation| operation.type == type }.size end |
#disable(feature, gate, thing) ⇒ Object
Public
72 73 74 75 |
# File 'lib/flipper/adapters/operation_logger.rb', line 72 def disable(feature, gate, thing) @operations << Operation.new(:disable, [feature, gate, thing]) @adapter.disable(feature, gate, thing) end |
#enable(feature, gate, thing) ⇒ Object
Public
66 67 68 69 |
# File 'lib/flipper/adapters/operation_logger.rb', line 66 def enable(feature, gate, thing) @operations << Operation.new(:enable, [feature, gate, thing]) @adapter.enable(feature, gate, thing) end |
#features ⇒ Object
Public: The set of known features.
35 36 37 38 |
# File 'lib/flipper/adapters/operation_logger.rb', line 35 def features @operations << Operation.new(:features, []) @adapter.features end |
#get(feature) ⇒ Object
Public
60 61 62 63 |
# File 'lib/flipper/adapters/operation_logger.rb', line 60 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.
48 49 50 51 |
# File 'lib/flipper/adapters/operation_logger.rb', line 48 def remove(feature) @operations << Operation.new(:remove, [feature]) @adapter.remove(feature) end |
#reset ⇒ Object
Public: Resets the operation log to empty
83 84 85 |
# File 'lib/flipper/adapters/operation_logger.rb', line 83 def reset @operations.clear end |