Sha256: e22c6b8406890bd18e98ac2bf6a75e3e4a5d4544df6a7a34c27bcda0ed03f892

Contents?: true

Size: 732 Bytes

Versions: 5

Compression:

Stored size: 732 Bytes

Contents

module FactoryGirl
  class Registry
    include Enumerable

    def initialize
      @items = {}
    end

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

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

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

    def [](name)
      find(name)
    end

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

    def clear
      @items.clear
    end

    private

    def add_as(name, item)
      if registered?(name)
        raise DuplicateDefinitionError, "Already defined: #{name}"
      else
        @items[name.to_sym] = item
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
factory_girl-2.0.0.beta5 lib/factory_girl/registry.rb
factory_girl-2.0.0.beta4 lib/factory_girl/registry.rb
factory_girl-2.0.0.beta3 lib/factory_girl/registry.rb
factory_girl_kibiz0r-2.0.0.beta3 lib/factory_girl/registry.rb
factory_girl_kibiz0r-2.0.0.beta2 lib/factory_girl/registry.rb