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

- (Registry) initialize(name)

Returns a new instance of 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

- (Object) name (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

- (Object) clear



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

def clear
  @items.clear
end

- (Object) each(&block)



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

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

- (Object) find(name) 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

- (Object) register(name, item)



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

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

- (Boolean) registered?(name)

Returns:

  • (Boolean)


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

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