Class: FactoryBotCaching::CacheManager

Inherits:
Object
  • Object
show all
Defined in:
lib/factory_bot_caching/cache_manager.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCacheManager



33
34
35
36
37
# File 'lib/factory_bot_caching/cache_manager.rb', line 33

def initialize
  @factory_cache = Hash.new do |hash, key|
    hash[key] = FactoryCache.new(factory_name: key)
  end
end

Class Method Details

.instanceObject



29
30
31
# File 'lib/factory_bot_caching/cache_manager.rb', line 29

def self.instance
  @instance ||= self.new
end

Instance Method Details

#fetch(name:, overrides:, traits:, &block) ⇒ Object



47
48
49
# File 'lib/factory_bot_caching/cache_manager.rb', line 47

def fetch(name:, overrides:, traits:, &block)
  factory_cache[name].fetch(overrides: overrides, traits: traits, &block)
end

#reset_cacheObject



39
40
41
# File 'lib/factory_bot_caching/cache_manager.rb', line 39

def reset_cache
  factory_cache.each_value(&:reset)
end

#reset_cache_counterObject



43
44
45
# File 'lib/factory_bot_caching/cache_manager.rb', line 43

def reset_cache_counter
  factory_cache.each_value(&:reset_counter)
end