Class: FactoryBot::Registry

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/factory_bot/registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Registry

Returns a new instance of Registry.



9
10
11
12
# File 'lib/factory_bot/registry.rb', line 9

def initialize(name)
  @name = name
  @items = ActiveSupport::HashWithIndifferentAccess.new
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/factory_bot/registry.rb', line 7

def name
  @name
end

Instance Method Details

#clearObject



14
15
16
# File 'lib/factory_bot/registry.rb', line 14

def clear
  @items.clear
end

#each(&block) ⇒ Object



18
19
20
# File 'lib/factory_bot/registry.rb', line 18

def each(&block)
  @items.values.uniq.each(&block)
end

#find(name) ⇒ Object Also known as: []



22
23
24
25
26
# File 'lib/factory_bot/registry.rb', line 22

def find(name)
  @items.fetch(name)
rescue KeyError => e
  raise key_error_with_custom_message(e)
end

#register(name, item) ⇒ Object



30
31
32
# File 'lib/factory_bot/registry.rb', line 30

def register(name, item)
  @items[name] = item
end

#registered?(name) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/factory_bot/registry.rb', line 34

def registered?(name)
  @items.key?(name)
end