Sha256: be0d4e6b37f8c29361bbb72ed227bda19587fde5b9defd4df660ade051c941e0

Contents?: true

Size: 1.26 KB

Versions: 101

Compression:

Stored size: 1.26 KB

Contents

class Avo::Reloader
  delegate :execute_if_updated, :execute, :updated?, to: :updater

  def reload!
    # reload all files declared in paths
    files.each do |file|
      if File.exist? file
        load file
      end
    end

    # reload all files declared in each directory
    directories.keys.each do |dir|
      Dir.glob("#{dir}/**/*.rb".to_s).each do |file|
        if File.exist? file
          load file
        end
      end
    end
  end

  private

  def updater
    @updater ||= config.file_watcher.new(files, directories) { reload! }
  end

  def files
    # we want to watch some files no matter what
    paths = [
      Rails.root.join("config", "initializers", "avo.rb"),
    ]

    # we want to watch some files only in Avo development
    if reload_lib?
      paths += []
    end

    paths
  end

  def directories
    dirs = {}

    # watch the lib directory in Avo development
    if reload_lib?
      dirs[Avo::Engine.root.join("lib", "avo").to_s] = ["rb"]
      if Avo.avo_dynamic_filters_installed?
        dirs[Avo::DynamicFilters::Engine.root.join("lib", "avo", "dynamic_filters").to_s] = ["rb"]
      end
    end

    dirs
  end

  def config
    Rails.application.config
  end

  def reload_lib?
    Avo::IN_DEVELOPMENT || ENV["AVO_RELOAD_LIB_DIR"]
  end
end

Version data entries

101 entries across 101 versions & 1 rubygems

Version Path
avo-3.10.6 lib/avo/reloader.rb
avo-3.10.5 lib/avo/reloader.rb
avo-3.10.4 lib/avo/reloader.rb
avo-3.10.3 lib/avo/reloader.rb
avo-3.10.2 lib/avo/reloader.rb
avo-3.10.1 lib/avo/reloader.rb
avo-3.10.0 lib/avo/reloader.rb
avo-3.9.2 lib/avo/reloader.rb
avo-3.9.1 lib/avo/reloader.rb
avo-3.8.2 lib/avo/reloader.rb
avo-3.9.0 lib/avo/reloader.rb
avo-3.8.1 lib/avo/reloader.rb
avo-3.8.0 lib/avo/reloader.rb
avo-3.6.4 lib/avo/reloader.rb
avo-3.6.3 lib/avo/reloader.rb
avo-3.6.2 lib/avo/reloader.rb
avo-3.6.1 lib/avo/reloader.rb
avo-3.6.0 lib/avo/reloader.rb
avo-3.5.8 lib/avo/reloader.rb
avo-3.5.7 lib/avo/reloader.rb