Class: GitCompound::Worker::ComponentDispatcher

Inherits:
Worker
  • Object
show all
Defined in:
lib/git_compound/worker/component_dispatcher.rb

Overview

Worker that decides whether component should be built, updated or replaced

Instance Method Summary collapse

Methods inherited from Worker

#visit_manifest, #visit_task

Constructor Details

#initialize(lock) ⇒ ComponentDispatcher



7
8
9
10
11
12
13
# File 'lib/git_compound/worker/component_dispatcher.rb', line 7

def initialize(lock)
  @lock    = lock
  @print   = PrettyPrint.new
  @build   = ComponentBuilder.new(lock)
  @update  = ComponentUpdater.new(lock)
  @replace = ComponentReplacer.new(lock)
end

Instance Method Details

#visit_component(component) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/git_compound/worker/component_dispatcher.rb', line 15

def visit_component(component)
  @component  = component
  @repository = component.repository if component.exists?

  case
  when component_needs_building?  then strategy = @build
  when component_needs_updating?  then strategy = @update
  when component_needs_replacing? then strategy = @replace
  else
    Logger.inline 'Unchanged: '
    @print.visit_component(component)
    @lock.lock_component(component)
    return
  end

  strategy.visit_component(component)
end