Class: Flipper::Adapters::OperationLogger
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- 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, :get_multi, :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.
-
#get_multi(features) ⇒ Object
Public.
-
#initialize(adapter, operations = nil) ⇒ OperationLogger
constructor
Public.
-
#last(type) ⇒ Object
Public: Get the last operation of a certain type.
-
#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
31 32 33 34 35 36 |
# File 'lib/flipper/adapters/operation_logger.rb', line 31 def initialize(adapter, operations = nil) super(adapter) @adapter = adapter @name = :operation_logger @operations = operations || [] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Internal: The name of the adapter.
28 29 30 |
# File 'lib/flipper/adapters/operation_logger.rb', line 28 def name @name end |
#operations ⇒ Object (readonly)
Internal: An array of the operations that have happened.
25 26 27 |
# File 'lib/flipper/adapters/operation_logger.rb', line 25 def operations @operations end |
Instance Method Details
#add(feature) ⇒ Object
Public: Adds a feature to the set of known features.
45 46 47 48 |
# File 'lib/flipper/adapters/operation_logger.rb', line 45 def add(feature) @operations << Operation.new(:add, [feature]) @adapter.add(feature) end |
#clear(feature) ⇒ Object
Public: Clears all the gate values for a feature.
58 59 60 61 |
# File 'lib/flipper/adapters/operation_logger.rb', line 58 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.
88 89 90 |
# File 'lib/flipper/adapters/operation_logger.rb', line 88 def count(type) @operations.select { |operation| operation.type == type }.size end |
#disable(feature, gate, thing) ⇒ Object
Public
82 83 84 85 |
# File 'lib/flipper/adapters/operation_logger.rb', line 82 def disable(feature, gate, thing) @operations << Operation.new(:disable, [feature, gate, thing]) @adapter.disable(feature, gate, thing) end |
#enable(feature, gate, thing) ⇒ Object
Public
76 77 78 79 |
# File 'lib/flipper/adapters/operation_logger.rb', line 76 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.
39 40 41 42 |
# File 'lib/flipper/adapters/operation_logger.rb', line 39 def features @operations << Operation.new(:features, []) @adapter.features end |
#get(feature) ⇒ Object
Public
64 65 66 67 |
# File 'lib/flipper/adapters/operation_logger.rb', line 64 def get(feature) @operations << Operation.new(:get, [feature]) @adapter.get(feature) end |
#get_multi(features) ⇒ Object
Public
70 71 72 73 |
# File 'lib/flipper/adapters/operation_logger.rb', line 70 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.
93 94 95 |
# File 'lib/flipper/adapters/operation_logger.rb', line 93 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.
52 53 54 55 |
# File 'lib/flipper/adapters/operation_logger.rb', line 52 def remove(feature) @operations << Operation.new(:remove, [feature]) @adapter.remove(feature) end |
#reset ⇒ Object
Public: Resets the operation log to empty
98 99 100 |
# File 'lib/flipper/adapters/operation_logger.rb', line 98 def reset @operations.clear end |