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, :get_all, :enable, :disable, ].freeze
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_all ⇒ 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.
Methods included from Flipper::Adapter
#default_config, #import, included
Constructor Details
#initialize(adapter, operations = nil) ⇒ OperationLogger
Public
32 33 34 35 36 37 |
# File 'lib/flipper/adapters/operation_logger.rb', line 32 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.
29 30 31 |
# File 'lib/flipper/adapters/operation_logger.rb', line 29 def name @name end |
#operations ⇒ Object (readonly)
Internal: An array of the operations that have happened.
26 27 28 |
# File 'lib/flipper/adapters/operation_logger.rb', line 26 def operations @operations end |
Instance Method Details
#add(feature) ⇒ Object
Public: Adds a feature to the set of known features.
46 47 48 49 |
# File 'lib/flipper/adapters/operation_logger.rb', line 46 def add(feature) @operations << Operation.new(:add, [feature]) @adapter.add(feature) end |
#clear(feature) ⇒ Object
Public: Clears all the gate values for a feature.
59 60 61 62 |
# File 'lib/flipper/adapters/operation_logger.rb', line 59 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.
95 96 97 |
# File 'lib/flipper/adapters/operation_logger.rb', line 95 def count(type) @operations.select { |operation| operation.type == type }.size end |
#disable(feature, gate, thing) ⇒ Object
Public
89 90 91 92 |
# File 'lib/flipper/adapters/operation_logger.rb', line 89 def disable(feature, gate, thing) @operations << Operation.new(:disable, [feature, gate, thing]) @adapter.disable(feature, gate, thing) end |
#enable(feature, gate, thing) ⇒ Object
Public
83 84 85 86 |
# File 'lib/flipper/adapters/operation_logger.rb', line 83 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.
40 41 42 43 |
# File 'lib/flipper/adapters/operation_logger.rb', line 40 def features @operations << Operation.new(:features, []) @adapter.features end |
#get(feature) ⇒ Object
Public
65 66 67 68 |
# File 'lib/flipper/adapters/operation_logger.rb', line 65 def get(feature) @operations << Operation.new(:get, [feature]) @adapter.get(feature) end |
#get_all ⇒ Object
Public
77 78 79 80 |
# File 'lib/flipper/adapters/operation_logger.rb', line 77 def get_all @operations << Operation.new(:get_all, []) @adapter.get_all end |
#get_multi(features) ⇒ Object
Public
71 72 73 74 |
# File 'lib/flipper/adapters/operation_logger.rb', line 71 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.
100 101 102 |
# File 'lib/flipper/adapters/operation_logger.rb', line 100 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.
53 54 55 56 |
# File 'lib/flipper/adapters/operation_logger.rb', line 53 def remove(feature) @operations << Operation.new(:remove, [feature]) @adapter.remove(feature) end |
#reset ⇒ Object
Public: Resets the operation log to empty
105 106 107 |
# File 'lib/flipper/adapters/operation_logger.rb', line 105 def reset @operations.clear end |