Sha256: 3194a897162296419065a2bbe8d699abca05c3dc094439d71cb5174fcbef555c
Contents?: true
Size: 1.15 KB
Versions: 1
Compression:
Stored size: 1.15 KB
Contents
require 'flipper/adapters/decorator' module Flipper module Adapters # Public: Adapter that wraps another adapter and stores the operations. # # Useful in tests to verify calls and such. Never use outside of testing. class OperationLogger < Decorator Operation = Struct.new(:type, :args) OperationTypes = [ :get, :add, :enable, :disable, :features ] # Internal: An array of the operations that have happened. attr_reader :operations # Public def initialize(adapter, operations = nil) super(adapter) @operations = operations || [] end OperationTypes.each do |type| class_eval <<-EOE def #{type}(*args) @operations << Operation.new(:#{type}, args) super end EOE end # Public: Count the number of times a certain operation happened. def count(type) @operations.select { |operation| operation.type == type }.size end # Public: Resets the operation log to empty def reset @operations.clear end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
flipper-0.5.0 | lib/flipper/adapters/operation_logger.rb |