module Etsource
  # Watches for changes to ETsource files. Changes made to dataset, gquery,
  # input, or topology files will clear out the caches, forcing these files to
  # be reloaded upon the next request.
  #
  # Works only on the current process, and is only available in the
  # development environment.
  #
  # @example
  #   Etsource::Reloader.start!
  #
  class Reloader
    class << self
      def start!
        return true if @listener

        @listener = Listen.to(ETSOURCE_EXPORT_DIR)
        @listener.filter(%r{(?:datasets|gqueries|inputs|topology)/.*})
        @listener.change { |*| reload! }
        @listener.start(false)

        Rails.logger.info 'ETsource live reload: Listener started.'

        true
      end

      def reload!
        Rails.cache.clear
        NastyCache.instance.expire!
        NastyCache.instance.expire_local!

        Rails.logger.info 'ETsource live reload: Caches cleared.'
      end
    end # class << self
  end # Reloader
end # Etsource

module Etsource
  # Watches for changes to ETsource files. Changes made to dataset, gquery,
  # input, or topology files will clear out the caches, forcing these files to
  # be reloaded upon the next request.
  #
  # Works only on the current process, and is only available in the
  # development environment.
  #
  # @example
  #   Etsource::Reloader.start!
  #
  class Reloader
    class << self
      def start!
        return true if @listener

        @listener = Listen.to(ETSOURCE_EXPORT_DIR)
        @listener.filter(%r{(?:datasets|gqueries|inputs|topology)/.*})
        @listener.change { |*| reload! }
        @listener.start(false)

        Rails.logger.info 'ETsource live reload: Listener started.'

        true
      end

      def reload!
        Rails.cache.clear
        NastyCache.instance.expire!
        NastyCache.instance.expire_local!

        Atlas::ActiveDocument::Manager.clear_all!

        Rails.logger.info 'ETsource live reload: Caches cleared.'
      end
    end # class << self
  end # Reloader
end # Etsource

Fix "live" reloading of inputs and gqueries
Fix "live" reloading of inputs and gqueries

Resolves quintel/etmodel#1500
