Class: ShopifyCLI::Theme::Extension::DevServer::Hooks::FileChangeHook

Inherits:
Object
  • Object
show all
Defined in:
lib/shopify_cli/theme/extension/dev_server/hooks/file_change_hook.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ctx, extension:, syncer:) ⇒ FileChangeHook

Returns a new instance of FileChangeHook.



11
12
13
14
15
# File 'lib/shopify_cli/theme/extension/dev_server/hooks/file_change_hook.rb', line 11

def initialize(ctx, extension:, syncer:)
  @ctx = ctx
  @extension = extension
  @syncer = syncer
end

Instance Attribute Details

#ctxObject (readonly)

Returns the value of attribute ctx.



9
10
11
# File 'lib/shopify_cli/theme/extension/dev_server/hooks/file_change_hook.rb', line 9

def ctx
  @ctx
end

#extensionObject (readonly)

Returns the value of attribute extension.



9
10
11
# File 'lib/shopify_cli/theme/extension/dev_server/hooks/file_change_hook.rb', line 9

def extension
  @extension
end

#streamsObject (readonly)

Returns the value of attribute streams.



9
10
11
# File 'lib/shopify_cli/theme/extension/dev_server/hooks/file_change_hook.rb', line 9

def streams
  @streams
end

#syncerObject (readonly)

Returns the value of attribute syncer.



9
10
11
# File 'lib/shopify_cli/theme/extension/dev_server/hooks/file_change_hook.rb', line 9

def syncer
  @syncer
end

Instance Method Details

#call(modified, added, removed, streams: nil) ⇒ Object



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

def call(modified, added, removed, streams: nil)
  @streams = streams

  modified = paths(modified).select { |file| @extension.extension_file?(file) }
  added = paths(added).select { |file| @extension.extension_file?(file) }
  removed = paths(removed)

  hot_reload(modified) unless modified.empty?
  reload_page(added, removed) unless (added + removed).empty?
end