Class: ShopifyCLI::Theme::Extension::DevServer::Watcher

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/shopify_cli/theme/extension/dev_server/watcher.rb

Overview

Watches for file changes and publish events to the theme

Instance Method Summary collapse

Constructor Details

#initialize(ctx, extension:, syncer:, poll: false) ⇒ Watcher

Returns a new instance of Watcher.



17
18
19
20
21
22
23
24
# File 'lib/shopify_cli/theme/extension/dev_server/watcher.rb', line 17

def initialize(ctx, extension:, syncer:, poll: false)
  @ctx = ctx
  @extension = extension
  @syncer = syncer
  @listener = FileSystemListener.new(root: @extension.root.to_s, force_poll: poll, ignore_regex: nil)

  add_observer(self, :notify_updates)
end

Instance Method Details

#files(paths) ⇒ Object



40
41
42
# File 'lib/shopify_cli/theme/extension/dev_server/watcher.rb', line 40

def files(paths)
  paths.map { |file| @extension[file] }
end

#notify_updates(modified, added, removed) ⇒ Object



34
35
36
37
38
# File 'lib/shopify_cli/theme/extension/dev_server/watcher.rb', line 34

def notify_updates(modified, added, removed)
  @syncer.enqueue_updates(files(modified).select { |file| @extension.extension_file?(file) })
  @syncer.enqueue_creates(files(added).select { |file| @extension.extension_file?(file) })
  @syncer.enqueue_deletes(files(removed))
end

#startObject



26
27
28
# File 'lib/shopify_cli/theme/extension/dev_server/watcher.rb', line 26

def start
  @listener.start
end

#stopObject



30
31
32
# File 'lib/shopify_cli/theme/extension/dev_server/watcher.rb', line 30

def stop
  @listener.stop
end