Class: Aspen::Actions::Watch

Inherits:
Object
  • Object
show all
Defined in:
lib/aspen/actions/watch.rb

Instance Method Summary collapse

Constructor Details

#initialize(options: {}) ⇒ Watch

Returns a new instance of Watch.



7
8
9
10
11
# File 'lib/aspen/actions/watch.rb', line 7

def initialize(options: {})
  @options = options
  @logger  = options.fetch(:logger) { Logger.new(STDOUT, level: :warn) }
  Listen.logger = @logger
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/aspen/actions/watch.rb', line 13

def call
  puts warning_message if using_database?

  listener = Listen.to('src/', only: /\.aspen$/) do |mod, add, _rem|
    Aspen::CLI::Commands::Build.new.call
    Aspen::Actions::Push.new.call
  rescue Aspen::Error => e
    puts e.message
  end

  listener.start
  sleep
rescue Interrupt => e
  # FIXME: The logger calls don't ever seem to work.
  @logger.info "Exiting..."
  puts "\nExiting..."
  listener.stop
  raise SystemExit
end