class GitCompound::Worker::ComponentDispatcher

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

Public Class Methods

new(lock) click to toggle source
# 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

Public Instance Methods

visit_component(component) click to toggle source
# 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

Private Instance Methods

component_needs_building?() click to toggle source

Component needs building if it's destination directory does not exist

# File lib/git_compound/worker/component_dispatcher.rb, line 38
def component_needs_building?
  !@component.exists?
end
component_needs_replacing?() click to toggle source

Component needs replacing if it exists but repository remote origin does not match new component origin

# File lib/git_compound/worker/component_dispatcher.rb, line 55
def component_needs_replacing?
  return false unless @component.exists?

  !(@repository.origin_remote =~ /#{@component.origin}$/)
end
component_needs_updating?() click to toggle source

Component needs updating if it exists, remote origin matches new component origin and HEAD sha has changed

# File lib/git_compound/worker/component_dispatcher.rb, line 45
def component_needs_updating?
  return false unless @component.exists?

  @repository.origin_remote =~ /#{@component.origin}$/ &&
    @repository.head_sha != @component.sha
end