Sha256: 1789c20f36a6f28c8daddceb8a692c6ecf372ee920839f52cc0d6a80c8f4dc66

Contents?: true

Size: 1.18 KB

Versions: 5

Compression:

Stored size: 1.18 KB

Contents

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

  include KuberKit::Import[
    "artifacts_sync.git_artifact_resolver",
    "artifacts_sync.null_artifact_resolver",

    "ui"
  ]

  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, artifact)
    add_default_resolvers

    resolver = @@resolvers[artifact.class]

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

    resolver.resolve(shell, artifact)
  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

5 entries across 5 versions & 1 rubygems

Version Path
kuber_kit-0.7.0 lib/kuber_kit/artifacts_sync/artifact_updater.rb
kuber_kit-0.6.4 lib/kuber_kit/artifacts_sync/artifact_updater.rb
kuber_kit-0.6.3 lib/kuber_kit/artifacts_sync/artifact_updater.rb
kuber_kit-0.6.2 lib/kuber_kit/artifacts_sync/artifact_updater.rb
kuber_kit-0.6.1 lib/kuber_kit/artifacts_sync/artifact_updater.rb