Sha256: d78d54fd2434e14dffe6393e4beeb983efab41dea27da6dbbe5358e356dcefb2

Contents?: true

Size: 1.08 KB

Versions: 9

Compression:

Stored size: 1.08 KB

Contents

class KuberKit::ArtifactsSync::ArtifactUpdater
  StrategyNotFoundError = Class.new(KuberKit::NotFoundError)

  include KuberKit::Import[
    "ui"
  ]

  def use_strategy(strategy, artifact_class:)
    @@strategies ||= {}

    if !strategy.is_a?(KuberKit::ArtifactsSync::Strategies::Abstract)
      raise ArgumentError.new("should be an instance of KuberKit::ArtifactsSync::Strategies::Abstract, got: #{strategy.inspect}")
    end

    @@strategies[artifact_class] = strategy
  end

  def update(shell, artifact)
    strategy = @@strategies[artifact.class]

    ui.print_debug "ArtifactUpdater", "Updating artifact #{artifact.name.to_s.green}"
    
    raise StrategyNotFoundError, "Can't find strategy for artifact #{artifact}" if strategy.nil?

    strategy.update(shell, artifact)
  end

  def cleanup(shell, artifact)
    strategy = @@strategies[artifact.class]

    ui.print_debug "ArtifactUpdater", "Cleaning artifact #{artifact.name.to_s.green}"
    
    raise StrategyNotFoundError, "Can't find strategy for artifact #{artifact}" if strategy.nil?

    strategy.cleanup(shell, artifact)
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
kuber_kit-1.3.8 lib/kuber_kit/artifacts_sync/artifact_updater.rb
kuber_kit-1.3.7 lib/kuber_kit/artifacts_sync/artifact_updater.rb
kuber_kit-1.1.8 lib/kuber_kit/artifacts_sync/artifact_updater.rb
kuber_kit-1.3.6 lib/kuber_kit/artifacts_sync/artifact_updater.rb
kuber_kit-1.1.7 lib/kuber_kit/artifacts_sync/artifact_updater.rb
kuber_kit-1.3.5 lib/kuber_kit/artifacts_sync/artifact_updater.rb
kuber_kit-1.3.4 lib/kuber_kit/artifacts_sync/artifact_updater.rb
kuber_kit-1.1.6 lib/kuber_kit/artifacts_sync/artifact_updater.rb
kuber_kit-1.3.3 lib/kuber_kit/artifacts_sync/artifact_updater.rb