Class: FactoryGirl::Registry

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Registry



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

def initialize(name)
  @name  = name
  @items = Decorator::ClassKeyHash.new({})
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name



5
6
7
# File 'lib/factory_girl/registry.rb', line 5

def name
  @name
end

Instance Method Details

#clearObject



12
13
14
# File 'lib/factory_girl/registry.rb', line 12

def clear
  @items.clear
end

#each(&block) ⇒ Object



16
17
18
# File 'lib/factory_girl/registry.rb', line 16

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

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



20
21
22
23
24
25
26
# File 'lib/factory_girl/registry.rb', line 20

def find(name)
  if registered?(name)
    @items[name]
  else
    raise ArgumentError, "#{@name} not registered: #{name}"
  end
end

#register(name, item) ⇒ Object



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

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

#registered?(name) ⇒ Boolean



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

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