class Flipper::Adapters::OperationLogger

Public: Adapter that wraps another adapter and stores the operations.

Useful in tests to verify calls and such. Never use outside of testing.

Constants

OperationTypes

Attributes

name[R]

Internal: The name of the adapter.

operations[R]

Internal: An array of the operations that have happened.

Public Class Methods

new(adapter, operations = nil) click to toggle source

Public

Calls superclass method
# File lib/flipper/adapters/operation_logger.rb, line 39
def initialize(adapter, operations = nil)
  super(adapter)
  @adapter = adapter
  @name = :operation_logger
  @operations = operations || []
end

Public Instance Methods

add(feature) click to toggle source

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

# File lib/flipper/adapters/operation_logger.rb, line 53
def add(feature)
  @operations << Operation.new(:add, [feature])
  @adapter.add(feature)
end
clear(feature) click to toggle source

Public: Clears all the gate values for a feature.

# File lib/flipper/adapters/operation_logger.rb, line 66
def clear(feature)
  @operations << Operation.new(:clear, [feature])
  @adapter.clear(feature)
end
count(type) click to toggle source

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

# File lib/flipper/adapters/operation_logger.rb, line 102
def count(type)
  type(type).size
end
disable(feature, gate, thing) click to toggle source

Public

# 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) click to toggle source

Public

# 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
features() click to toggle source

Public: The set of known features.

# File lib/flipper/adapters/operation_logger.rb, line 47
def features
  @operations << Operation.new(:features, [])
  @adapter.features
end
get(feature) click to toggle source

Public

# File lib/flipper/adapters/operation_logger.rb, line 72
def get(feature)
  @operations << Operation.new(:get, [feature])
  @adapter.get(feature)
end
get_all() click to toggle source

Public

# File lib/flipper/adapters/operation_logger.rb, line 84
def get_all
  @operations << Operation.new(:get_all, [])
  @adapter.get_all
end
get_multi(features) click to toggle source

Public

# File lib/flipper/adapters/operation_logger.rb, line 78
def get_multi(features)
  @operations << Operation.new(:get_multi, [features])
  @adapter.get_multi(features)
end
inspect() click to toggle source
# File lib/flipper/adapters/operation_logger.rb, line 121
def inspect
  inspect_id = ::Kernel::format "%x", (object_id * 2)
  %(#<#{self.class}:0x#{inspect_id} @name=#{name.inspect}, @operations=#{@operations.inspect}, @adapter=#{@adapter.inspect}>)
end
last(type) click to toggle source

Public: Get the last operation of a certain type.

# File lib/flipper/adapters/operation_logger.rb, line 112
def last(type)
  @operations.reverse.find { |operation| operation.type == type }
end
remove(feature) click to toggle source

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

# File lib/flipper/adapters/operation_logger.rb, line 60
def remove(feature)
  @operations << Operation.new(:remove, [feature])
  @adapter.remove(feature)
end
reset() click to toggle source

Public: Resets the operation log to empty

# File lib/flipper/adapters/operation_logger.rb, line 117
def reset
  @operations.clear
end
type(type) click to toggle source

Public: Get all operations of a certain type.

# File lib/flipper/adapters/operation_logger.rb, line 107
def type(type)
  @operations.select { |operation| operation.type == type }
end