Sha256: 9e2ffd57a9c4323213a406c4698db540c01bab17a4e3245f5a69bb3e7dd15371

Contents?: true

Size: 1005 Bytes

Versions: 2

Compression:

Stored size: 1005 Bytes

Contents

require 'listen'

module Fontcustom
  class Watcher
    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
        @listener.start()

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

    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fontcustom-0.0.2 lib/fontcustom/watcher.rb
fontcustom-0.0.1 lib/fontcustom/watcher.rb