Sha256: 77401dae8b63daf40b3567d0b8aa4899d80ed2f2ffe401b3f410c690af81f4c3

Contents?: true

Size: 1.11 KB

Versions: 95

Compression:

Stored size: 1.11 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"]
    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

95 entries across 95 versions & 1 rubygems

Version Path
avo-2.36.2 lib/avo/reloader.rb
avo-2.36.1 lib/avo/reloader.rb
avo-2.36.0 lib/avo/reloader.rb
avo-2.35.0 lib/avo/reloader.rb
avo-2.34.7.pre.1 lib/avo/reloader.rb
avo-2.34.6 lib/avo/reloader.rb
avo-2.34.5 lib/avo/reloader.rb
avo-2.34.4 lib/avo/reloader.rb
avo-2.34.4.pre.1 lib/avo/reloader.rb
avo-2.34.3 lib/avo/reloader.rb
avo-2.34.2 lib/avo/reloader.rb
avo-2.34.1 lib/avo/reloader.rb
avo-2.34.0 lib/avo/reloader.rb
avo-2.33.3 lib/avo/reloader.rb
avo-2.33.3.pre.2 lib/avo/reloader.rb
avo-2.33.3.pre.1 lib/avo/reloader.rb
avo-2.33.2 lib/avo/reloader.rb
avo-2.33.1 lib/avo/reloader.rb
avo-2.33.0 lib/avo/reloader.rb
avo-2.32.6 lib/avo/reloader.rb