Module: FactoryBotCaching

Defined in:
lib/factory_bot_caching/config.rb,
lib/factory_bot_caching.rb,
lib/factory_bot_caching/version.rb,
lib/factory_bot_caching/cache_manager.rb,
lib/factory_bot_caching/factory_cache.rb,
lib/factory_bot_caching/module_methods.rb,
lib/factory_bot_caching/customized_cache.rb,
lib/factory_bot_caching/immutable_iterator.rb,
lib/factory_bot_caching/factory_record_cache.rb,
lib/factory_bot_caching/caching_factory_runner.rb

Overview

The MIT License (MIT)

Copyright © 2017-2018 Avant

Author Tim Mertens

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Defined Under Namespace

Modules: CachingFactoryRunner Classes: CacheManager, Config, CustomizedCache, FactoryCache, FactoryRecordCache, ImmutableIterator

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.configurationObject



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

def configuration
  @configuration ||= Config.new
end

.configure {|configuration| ... } ⇒ Object

Yields:

Raises:

  • (ArgumentError)


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

def configure(&block)
  raise ArgumentError, 'You must supply a block!' unless block_given?
  yield configuration
end

.enabled?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/factory_bot_caching/module_methods.rb', line 38

def enabled?
  configuration.factory_caching_enabled?
end

.initializeObject



31
32
33
# File 'lib/factory_bot_caching.rb', line 31

def self.initialize
  FactoryGirl::FactoryRunner.prepend(FactoryBotCaching::CachingFactoryRunner)
end

.without_caching(&block) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/factory_bot_caching/module_methods.rb', line 42

def without_caching(&block)
  original_caching_value = configuration.factory_caching_enabled?
  configuration.disable_factory_caching
  block.call
ensure
  configuration.enable_factory_caching if original_caching_value
end