Class: ShopifyCLI::Theme::Extension::Syncer

Inherits:
Object
  • Object
show all
Defined in:
lib/shopify_cli/theme/extension/syncer.rb,
lib/shopify_cli/theme/extension/syncer/operation.rb,
lib/shopify_cli/theme/extension/syncer/extension_serve_job.rb

Defined Under Namespace

Classes: ExtensionServeJob, Operation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ctx, extension:, project:, specification_handler:) ⇒ Syncer

Returns a new instance of Syncer.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/shopify_cli/theme/extension/syncer.rb', line 14

def initialize(ctx, extension:, project:, specification_handler:)
  @ctx = ctx
  @extension = extension
  @project = project
  @specification_handler = specification_handler

  @pool = ThreadPool.new(pool_size: 1)
  @pending_operations = extension.extension_files.map { |file| Operation.new(file, :update) }
  @pending_operations_mutex = Mutex.new
  @latest_sync = Time.now - ExtensionServeJob::PUSH_INTERVAL
end

Instance Attribute Details

#latest_syncObject

Returns the value of attribute latest_sync.



12
13
14
# File 'lib/shopify_cli/theme/extension/syncer.rb', line 12

def latest_sync
  @latest_sync
end

#pending_operationsObject

Returns the value of attribute pending_operations.



12
13
14
# File 'lib/shopify_cli/theme/extension/syncer.rb', line 12

def pending_operations
  @pending_operations
end

Instance Method Details

#any_blocking_operation?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/shopify_cli/theme/extension/syncer.rb', line 57

def any_blocking_operation?
  pending_operations.any? { |operation| operation.delete? || operation.create? }
end

#any_operation?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/shopify_cli/theme/extension/syncer.rb', line 53

def any_operation?
  pending_operations.any?
end

#enqueue_creates(files) ⇒ Object



26
27
28
29
# File 'lib/shopify_cli/theme/extension/syncer.rb', line 26

def enqueue_creates(files)
  operations = files.map { |file| Operation.new(file, :create) }
  enqueue_operations(operations)
end

#enqueue_deletes(files) ⇒ Object



36
37
38
39
# File 'lib/shopify_cli/theme/extension/syncer.rb', line 36

def enqueue_deletes(files)
  operations = files.map { |file| Operation.new(file, :delete) }
  enqueue_operations(operations)
end

#enqueue_updates(files) ⇒ Object



31
32
33
34
# File 'lib/shopify_cli/theme/extension/syncer.rb', line 31

def enqueue_updates(files)
  operations = files.map { |file| Operation.new(file, :update) }
  enqueue_operations(operations)
end

#pending_filesObject



49
50
51
# File 'lib/shopify_cli/theme/extension/syncer.rb', line 49

def pending_files
  pending_operations.map(&:file)
end

#shutdownObject



45
46
47
# File 'lib/shopify_cli/theme/extension/syncer.rb', line 45

def shutdown
  @pool.shutdown
end

#startObject



41
42
43
# File 'lib/shopify_cli/theme/extension/syncer.rb', line 41

def start
  @pool.schedule(job)
end