Module: FactoryBotCache
- Defined in:
- lib/factory_bot_cache.rb,
lib/factory_bot_cache/version.rb
Constant Summary collapse
- VERSION =
"0.1.1"
Class Method Summary collapse
- .caches ⇒ Object
- .clear ⇒ Object
-
.id_map_of(base_name) ⇒ Proc
A Proc which returns mapped id for given argument.
- .naming_rules ⇒ Object
- .of(base_name) ⇒ Object
Class Method Details
.caches ⇒ Object
18 19 20 |
# File 'lib/factory_bot_cache.rb', line 18 def caches @caches ||= {} end |
.clear ⇒ Object
8 9 10 |
# File 'lib/factory_bot_cache.rb', line 8 def clear @caches = nil end |
.id_map_of(base_name) ⇒ Proc
Returns a Proc which returns mapped id for given argument.
30 31 32 |
# File 'lib/factory_bot_cache.rb', line 30 def id_map_of(base_name) lambda{|key| of(base_name)[key].id } end |
.naming_rules ⇒ Object
12 13 14 15 16 |
# File 'lib/factory_bot_cache.rb', line 12 def naming_rules @naming_rules ||= Hash.new do |hash, base_name| hash[base_name] = ->(key){ "#{base_name}_#{key}" } end end |
.of(base_name) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/factory_bot_cache.rb', line 22 def of(base_name) caches[base_name.to_sym] ||= Hash.new do |hash, key| naming_rule = naming_rules[base_name.to_sym] hash[key] = FactoryBot.create( naming_rule[key] ) end end |