Sha256: b4e1cf174e7f66babeaae7c077ce7ceee4c3d3a493eb027a6ecbd98d8b5674a1

Contents?: true

Size: 1.22 KB

Versions: 32

Compression:

Stored size: 1.22 KB

Contents

class KuberKit::ArtifactsSync::ArtifactsUpdater
  ResolverNotFoundError = Class.new(KuberKit::NotFoundError)

  include KuberKit::Import[
    "artifacts_sync.git_artifact_resolver",
    "artifacts_sync.null_artifact_resolver",
    "tools.logger"
  ]

  def use_resolver(artifact_resolver, artifact_class:)
    @@resolvers ||= {}

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

    @@resolvers[artifact_class] = artifact_resolver
  end

  def update(shell, artifacts)
    add_default_resolvers

    artifacts.each do |artifact|
      resolver = @@resolvers[artifact.class]

      logger.info "Updating artifact #{artifact.name.to_s.green}"
      
      raise ResolverNotFoundError, "Can't find resolver for artifact #{artifact}" if resolver.nil?

      resolver.resolve(shell, artifact)
    end
  end

  def add_default_resolvers
    use_resolver(git_artifact_resolver, artifact_class: KuberKit::Core::Artifacts::Git)
    use_resolver(null_artifact_resolver, artifact_class: KuberKit::Core::Artifacts::Local)
  end

  def reset!
    @@resolvers = {}
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
kuber_kit-0.3.11 lib/kuber_kit/artifacts_sync/artifacts_updater.rb
kuber_kit-0.3.10 lib/kuber_kit/artifacts_sync/artifacts_updater.rb
kuber_kit-0.3.9 lib/kuber_kit/artifacts_sync/artifacts_updater.rb
kuber_kit-0.3.8 lib/kuber_kit/artifacts_sync/artifacts_updater.rb
kuber_kit-0.3.7 lib/kuber_kit/artifacts_sync/artifacts_updater.rb
kuber_kit-0.3.6 lib/kuber_kit/artifacts_sync/artifacts_updater.rb
kuber_kit-0.3.5 lib/kuber_kit/artifacts_sync/artifacts_updater.rb
kuber_kit-0.3.4 lib/kuber_kit/artifacts_sync/artifacts_updater.rb
kuber_kit-0.3.3 lib/kuber_kit/artifacts_sync/artifacts_updater.rb
kuber_kit-0.3.2 lib/kuber_kit/artifacts_sync/artifacts_updater.rb
kuber_kit-0.3.1 lib/kuber_kit/artifacts_sync/artifacts_updater.rb
kuber_kit-0.3.0 lib/kuber_kit/artifacts_sync/artifacts_updater.rb
kuber_kit-0.2.9 lib/kuber_kit/artifacts_sync/artifacts_updater.rb
kuber_kit-0.2.8 lib/kuber_kit/artifacts_sync/artifacts_updater.rb
kuber_kit-0.2.7 lib/kuber_kit/artifacts_sync/artifacts_updater.rb
kuber_kit-0.2.6 lib/kuber_kit/artifacts_sync/artifacts_updater.rb
kuber_kit-0.2.5 lib/kuber_kit/artifacts_sync/artifacts_updater.rb
kuber_kit-0.2.4 lib/kuber_kit/artifacts_sync/artifacts_updater.rb
kuber_kit-0.2.3 lib/kuber_kit/artifacts_sync/artifacts_updater.rb
kuber_kit-0.2.2 lib/kuber_kit/artifacts_sync/artifacts_updater.rb