Class: Fontcustom::Watcher

Inherits:
Object
  • Object
show all
Defined in:
lib/fontcustom/watcher.rb

Class Method Summary collapse

Class Method Details

.stopObject



30
31
32
33
34
# File 'lib/fontcustom/watcher.rb', line 30

def self.stop
  # Newline exists so message is not prepended with ^C on SIGTERM
  puts "\nFontcustom is signing off. Goodnight and good luck."
  @listener.stop
end

.watch(*args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fontcustom/watcher.rb', line 5

def self.watch(*args)
  callback = Proc.new do |modified, added, removed|
    puts '    >> Changed: ' + modified.join(' ') unless modified.empty?
    puts '    >> Added: ' + added.join(' ') unless added.empty?
    puts '    >> Removed: ' + removed.join(' ') unless removed.empty?

    changed = modified + added + removed
    Fontcustom.compile(*args) unless changed.empty?
  end

  dir = args.first
  @listener = Listen.to(dir).filter(/\.(eps|svg)$/).change(&callback)

  begin
    puts "Fontcustom is watching your icons at " + dir
    Fontcustom.compile(*args)
    @listener.start()

  # Catches Cmd/Ctrl + C
  # Does listen gem have a better way of handling this?
  rescue SignalException
    stop
  end
end