You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
958 B
33 lines
958 B
module RailsLiveReload
|
|
ENV_FILE = Rails.root.join('.env').to_s
|
|
ENV_SAMPLE_FILE = Rails.root.join('.env.sample').to_s
|
|
CHECKSUMS = {}
|
|
|
|
# MonkeyPath Watcher
|
|
class Watcher
|
|
def reload_all
|
|
before_reload(files)
|
|
data = { event: RailsLiveReload::INTERNAL[:socket_events][:reload], files: }.to_json
|
|
@sockets.each { |socket, _| socket.puts data } # rubocop:disable Style/HashEachMethods
|
|
end
|
|
|
|
private
|
|
|
|
def before_reload(files)
|
|
if files.include?(ENV_SAMPLE_FILE)
|
|
current_checksum = files[ENV_SAMPLE_FILE]
|
|
if current_checksum != CHECKSUMS[ENV_SAMPLE_FILE]
|
|
HotConstants.initialize
|
|
CHECKSUMS[ENV_SAMPLE_FILE] = current_checksum
|
|
end
|
|
end
|
|
return unless files.include?(ENV_FILE)
|
|
|
|
current_checksum = files[ENV_FILE]
|
|
return unless current_checksum != CHECKSUMS[ENV_FILE]
|
|
|
|
HotConstants.reload!
|
|
CHECKSUMS[ENV_FILE] = current_checksum
|
|
end
|
|
end
|
|
end
|