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

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
  1. module RailsLiveReload
  2. ENV_FILE = Rails.root.join('.env').to_s
  3. ENV_SAMPLE_FILE = Rails.root.join('.env.sample').to_s
  4. CHECKSUMS = {}
  5. # MonkeyPath Watcher
  6. class Watcher
  7. def reload_all
  8. before_reload(files)
  9. data = { event: RailsLiveReload::INTERNAL[:socket_events][:reload], files: }.to_json
  10. @sockets.each { |socket, _| socket.puts data } # rubocop:disable Style/HashEachMethods
  11. end
  12. private
  13. def before_reload(files)
  14. if files.include?(ENV_SAMPLE_FILE)
  15. current_checksum = files[ENV_SAMPLE_FILE]
  16. if current_checksum != CHECKSUMS[ENV_SAMPLE_FILE]
  17. HotConstants.initialize
  18. CHECKSUMS[ENV_SAMPLE_FILE] = current_checksum
  19. end
  20. end
  21. return unless files.include?(ENV_FILE)
  22. current_checksum = files[ENV_FILE]
  23. return unless current_checksum != CHECKSUMS[ENV_FILE]
  24. HotConstants.reload!
  25. CHECKSUMS[ENV_FILE] = current_checksum
  26. end
  27. end
  28. end