Sha256: c48c97b50a148ecf709c7fcba713d4dc472e5ae2709c04dd0ff90ab2bd3a1b40

Contents?: true

Size: 838 Bytes

Versions: 2

Compression:

Stored size: 838 Bytes

Contents

# frozen_string_literal: true

require "factory_bot_rails/definition_file_paths"

module FactoryBotRails
  class Reloader
    def initialize(app, config)
      @app = app
      @config = config
      @paths = DefinitionFilePaths.new(FactoryBot.definition_file_paths)
    end

    def run
      return unless @paths.any?

      register_reloader(build_reloader)
    end

    private

    attr_reader :app, :config

    def build_reloader
      reloader_class.new(@paths.files, @paths.directories) do
        FactoryBot.reload
      end
    end

    def reloader_class
      app.config.file_watcher
    end

    def register_reloader(reloader)
      closed_over_app = app

      config.to_prepare do
        if closed_over_app.initialized?
          reloader.execute
        end
      end

      app.reloaders << reloader
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
factory_bot_rails-5.2.0 lib/factory_bot_rails/reloader.rb
factory_bot_rails-5.1.1 lib/factory_bot_rails/reloader.rb