1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot_rails.git synced 2022-11-09 11:49:18 -05:00
thoughtbot--factory_bot_rails/lib/factory_bot_rails/reloader.rb
yuuji.yaginuma 9b83f482b5 Do not register a reloader when file paths not exist
If all the paths specified in `FactoryBot.definition_file_paths` do not
exist, an empty array is passed to the reloader.

If an empty array is specified, reloader passes it to `Listen.to` as it
is. This causes the application root to be watched and `node_modules` to
become a target of listening.

The behavior when an empty array is passed to reloader depends on the
Rails side. Fixes to not register a reloader when file paths do not exist
consistent behavior regardless of Rails side.

Fixes #328.
2019-04-09 10:39:51 -04:00

41 lines
755 B
Ruby

# 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)
config.to_prepare do
reloader.execute
end
app.reloaders << reloader
end
end
end