Class: FactoryGirl::Registry

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

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Registry

Returns a new instance of Registry.



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

def initialize(name)
  @name  = name
  @items = {}
end

Instance Method Details

#[](name) ⇒ Object



23
24
25
# File 'lib/factory_girl/registry.rb', line 23

def [](name)
  find(name)
end

#add(item) ⇒ Object



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

def add(item)
  item.names.each { |name| add_as(name, item) }
  item
end

#clearObject



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

def clear
  @items.clear
end

#each(&block) ⇒ Object



19
20
21
# File 'lib/factory_girl/registry.rb', line 19

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

#find(name) ⇒ Object



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

def find(name)
  @items[name.to_sym] or raise ArgumentError.new("#{@name} not registered: #{name.to_s}")
end

#registered?(name) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/factory_girl/registry.rb', line 27

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