Sha256: cbd94991e610f5a3b95d05b7a291b387d9237cd03158037cae2f906b8e29ea3a

Contents?: true

Size: 737 Bytes

Versions: 12

Compression:

Stored size: 737 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.uniq.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

12 entries across 12 versions & 1 rubygems

Version Path
factory_girl-2.2.0 lib/factory_girl/registry.rb
factory_girl-2.1.2 lib/factory_girl/registry.rb
factory_girl-2.1.0 lib/factory_girl/registry.rb
factory_girl-2.0.5 lib/factory_girl/registry.rb
factory_girl-2.0.4 lib/factory_girl/registry.rb
factory_girl-2.0.3 lib/factory_girl/registry.rb
factory_girl-2.0.2 lib/factory_girl/registry.rb
factory_girl-2.0.1 lib/factory_girl/registry.rb
factory_girl-2.0.0.rc4 lib/factory_girl/registry.rb
factory_girl-2.0.0.rc3 lib/factory_girl/registry.rb
factory_girl-2.0.0.rc2 lib/factory_girl/registry.rb
factory_girl-2.0.0.rc1 lib/factory_girl/registry.rb