Sha256: f3cbe9b55e0322bceeb05a762cda5939fe54657b9749b67e3bab5a8dc2a1db57
Contents?: true
Size: 1.03 KB
Versions: 12
Compression:
Stored size: 1.03 KB
Contents
module Lookbook class FileWatcher attr_reader :listeners, :force_polling def initialize(force_polling: false) @force_polling = force_polling @listeners = [] end def watch(paths, extensions = ".*", opts = nil, &block) paths = PathUtils.normalize_paths(paths) if paths.any? opts = opts.to_h opts[:only] = /\.(#{Array(extensions).join("|")})$/ listeners << init_listener(paths, opts, &block) end end def start if listeners.any? Lookbook.logger.debug "Starting listeners" listeners.each { |l| l.start } end end def stop if listeners.any? Lookbook.logger.debug "Stopping listeners" listeners.each { |l| l.stop } end end protected def init_listener(paths, opts, &block) Listen.to( *paths, **opts, force_polling: force_polling ) do |modified, added, removed| block.call({modified: modified, added: added, removed: removed}) end end end end
Version data entries
12 entries across 12 versions & 1 rubygems