Sha256: 5fe0db8701de13a96f6c23b5ab429ae8eefe6e0db8d1991b6382683364f650db
Contents?: true
Size: 896 Bytes
Versions: 2
Compression:
Stored size: 896 Bytes
Contents
require "active_support/core_ext/hash/indifferent_access" module FactoryBot class Registry include Enumerable attr_reader :name def initialize(name) @name = name @items = ActiveSupport::HashWithIndifferentAccess.new end def clear @items.clear end def each(&block) @items.values.uniq.each(&block) end def find(name) @items.fetch(name) rescue KeyError => e raise key_error_with_custom_message(e) end alias_method :[], :find def register(name, item) @items[name] = item end def registered?(name) @items.key?(name) end private def key_error_with_custom_message(key_error) message = key_error.message.sub("key not found", "#{@name} not registered") error = KeyError.new(message) error.set_backtrace(key_error.backtrace) error end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
factory_bot-6.2.1 | lib/factory_bot/registry.rb |
factory_bot-6.2.0 | lib/factory_bot/registry.rb |