Class: Fontcustom::Watcher

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

Instance Method Summary collapse

Methods included from Util

#check_fontforge, #expand_path, #overwrite_file, #relative_to_root, #say_changed, #symbolize_hash

Constructor Details

#initialize(opts) ⇒ Watcher

Returns a new instance of Watcher.



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

def initialize(opts)
  @opts = opts
  @vector_listener = Listen.to(@opts.input[:vectors]).relative_paths(true).filter(/\.(eps|svg)$/).change(&callback)

  templates = @opts.templates.dup
  templates.delete_if do |template|
    template.match Fontcustom.gem_lib
  end
  unless templates.empty?
    templates = templates.map do |template|
      File.basename template
    end
    @template_listener = Listen.to(@opts.input[:templates]).relative_paths(true).filter(/(#{templates.join("|")})/).change(&callback)
  end

  # Modified to allow testing
  @is_test = @opts.instance_variable_get :@is_test
  if @is_test
    @vector_listener = @vector_listener.polling_fallback_message(false)
    @template_listener = @template_listener.polling_fallback_message(false) if @template_listener
  end
end

Instance Method Details

#watchObject



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

def watch
  compile unless @opts.skip_first
  start
rescue SignalException # Catches Ctrl + C
  stop
end