1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00
thoughtbot--factory_bot/lib/factory_bot/registry.rb

39 lines
607 B
Ruby
Raw Normal View History

module FactoryBot
class Registry
include Enumerable
attr_reader :name
def initialize(name)
@name = name
@items = Decorator::ClassKeyHash.new({})
end
2012-04-22 17:44:03 -04:00
def clear
@items.clear
end
def each(&block)
@items.values.uniq.each(&block)
end
def find(name)
2012-04-22 17:44:03 -04:00
if registered?(name)
@items[name]
2012-04-22 17:44:03 -04:00
else
raise ArgumentError, "#{@name} not registered: #{name}"
end
end
2012-04-23 16:33:12 -04:00
alias :[] :find
2012-04-22 17:44:03 -04:00
def register(name, item)
@items[name] = item
end
def registered?(name)
@items.key?(name)
end
end
end