Sha256: 193712021bc4345ccd09218eee05637a381fa29b16d73598fae7205d2c0398d4

Contents?: true

Size: 661 Bytes

Versions: 5

Compression:

Stored size: 661 Bytes

Contents

class Spring
  class ApplicationWatcher
    attr_reader :mtime, :files, :globs

    def initialize
      @files = []
      @globs = []
      @mtime = nil
    end

    def add_files(new_files)
      files.concat new_files.select { |f| File.exist?(f) }
      files.uniq!
      reset
    end

    def add_globs(new_globs)
      globs.concat new_globs
      reset
    end

    def reset
      @mtime = compute_mtime
    end

    def stale?
      mtime < compute_mtime
    end

    private

    def compute_mtime
      expanded_files.map { |f| File.mtime(f).to_f }.max || 0
    end

    def expanded_files
      files + Dir["{#{globs.join(",")}}"]
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spring-0.0.5 lib/spring/application_watcher.rb
spring-0.0.4 lib/spring/application_watcher.rb
spring-0.0.3 lib/spring/application_watcher.rb
spring-0.0.2 lib/spring/application_watcher.rb
spring-0.0.1 lib/spring/application_watcher.rb