Class: EacRailsGemSupport::FactoryBot::InstanceRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/eac_rails_gem_support/factory_bot/instance_registry.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.defaultObject



9
10
11
# File 'lib/eac_rails_gem_support/factory_bot/instance_registry.rb', line 9

def default
  @default ||= ::EacRailsGemSupport::FactoryBot::InstanceRegistry.new
end

.sanitize_key(key) ⇒ Object



15
16
17
# File 'lib/eac_rails_gem_support/factory_bot/instance_registry.rb', line 15

def sanitize_key(key)
  key.to_sym
end

Instance Method Details

#fetch(key) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/eac_rails_gem_support/factory_bot/instance_registry.rb', line 20

def fetch(key)
  key = self.class.sanitize_key(key)
  if fetched.key?(key)
    fetched.fetch(key)
  else
    fetched[key] = ::FactoryBot.create(key)
  end
end

#resetObject



29
30
31
# File 'lib/eac_rails_gem_support/factory_bot/instance_registry.rb', line 29

def reset
  @fetched = nil
end