Class: Gloss::Watcher
- Inherits:
-
Object
- Object
- Gloss::Watcher
- Defined in:
- lib/gloss/watcher.rb
Instance Method Summary collapse
-
#initialize(paths) ⇒ Watcher
constructor
A new instance of Watcher.
- #watch ⇒ Object
Constructor Details
Instance Method Details
#watch ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/gloss/watcher.rb', line 15 def watch() puts("=====> Now listening for changes in #{@paths.join(", ")}") listener = Listen.to(*@paths, latency: 2) { |modified, added, removed| modified.+(added) .each() { |f| unless f.end_with?(".gl") next end puts("====> Rewriting #{f}") content = File.read(f) Writer.new(Builder.new(Parser.new(content) .run) .run, f) .run puts("====> Done") } removed.each() { |f| unless f.end_with?(".gl") next end out_path = Utils.src_path_to_output_path(f) puts("====> Removing #{out_path}") (if File.exist?(out_path) File.delete(out_path) end) puts("====> Done") } } listener.start begin loop() { || sleep(10) } rescue Interrupt puts("=====> Interrupt signal received, shutting down") exit(0) end end |