Sha256: 6e20bf8d92b03ca9204d49aa14d8cc3736f9aaa20dd46872308336d53bcb8566

Contents?: true

Size: 734 Bytes

Versions: 10

Compression:

Stored size: 734 Bytes

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module EacRailsGemSupport
  module FactoryBot
    class InstanceRegistry
      class << self
        def default
          @default ||= ::EacRailsGemSupport::FactoryBot::InstanceRegistry.new
        end

        delegate :fetch, :reset, to: :default

        def sanitize_key(key)
          key.to_sym
        end
      end

      def fetch(key)
        key = self.class.sanitize_key(key)
        if fetched.key?(key)
          fetched.fetch(key)
        else
          fetched[key] = ::FactoryBot.create(key)
        end
      end

      def reset
        @fetched = nil
      end

      private

      def fetched
        @fetched ||= {}
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
eac_rails_gem_support-0.10.1 lib/eac_rails_gem_support/factory_bot/instance_registry.rb
eac_rails_gem_support-0.10.0 lib/eac_rails_gem_support/factory_bot/instance_registry.rb
eac_rails_gem_support-0.9.2 lib/eac_rails_gem_support/factory_bot/instance_registry.rb
eac_rails_gem_support-0.9.1 lib/eac_rails_gem_support/factory_bot/instance_registry.rb
eac_rails_gem_support-0.9.0 lib/eac_rails_gem_support/factory_bot/instance_registry.rb
eac_rails_gem_support-0.8.0 lib/eac_rails_gem_support/factory_bot/instance_registry.rb
eac_rails_gem_support-0.7.2 lib/eac_rails_gem_support/factory_bot/instance_registry.rb
eac_rails_gem_support-0.7.1 lib/eac_rails_gem_support/factory_bot/instance_registry.rb
eac_rails_gem_support-0.7.0 lib/eac_rails_gem_support/factory_bot/instance_registry.rb
eac_rails_gem_support-0.6.0 lib/eac_rails_gem_support/factory_bot/instance_registry.rb