Class: Js2coffee::Watcher
- Inherits:
-
Object
- Object
- Js2coffee::Watcher
- Includes:
- Singleton
- Defined in:
- lib/js2coffee/watcher.rb
Instance Method Summary collapse
-
#initialize ⇒ Watcher
constructor
A new instance of Watcher.
-
#start_watch_files ⇒ Object
watch all exist files modify event.
- #watched_files ⇒ Object
Constructor Details
#initialize ⇒ Watcher
Returns a new instance of Watcher.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/js2coffee/watcher.rb', line 11 def initialize @notifier = INotify::Notifier.new Signal.trap(2) {|_sig| Process.exit } start_watch_files @notifier.watch('.', :moved_from, :moved_to, :create, :delete, :onlydir, :recursive) do |event| # skip temp file. next if event.name =~ /^\.#|^#.*\#$/ start_watch_files end watched_files.each do |file| Js2coffee.watch_file(file) end # start loop. @notifier.run puts 'Watcher is started.' end |
Instance Method Details
#start_watch_files ⇒ Object
watch all exist files modify event.
35 36 37 38 39 40 41 |
# File 'lib/js2coffee/watcher.rb', line 35 def start_watch_files watched_files.each do |file| @notifier.watch(file, :modify) do Js2coffee.watch_file(file) end end end |
#watched_files ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/js2coffee/watcher.rb', line 43 def watched_files watched_files = Dir["./**/*.#{$script_extname}"] exclude_pattern = ['node_modules|bower_components'] << ENV['JS2COFFEE_EXCLUDE_PATTERN'] watched_files.reject! {|e| e =~ /#{exclude_pattern.join('|')}/ } watched_files end |