Sha256: fcde3744c4397a0d7b3dc53c176e6f6206f14b4a6f753741fffbca8199719900

Contents?: true

Size: 1016 Bytes

Versions: 1

Compression:

Stored size: 1016 Bytes

Contents

class KuberKit::TemplateReader::Reader
  ReaderNotFoundError = Class.new(KuberKit::NotFoundError)

  include KuberKit::Import[
    "template_reader.strategies.artifact_file",
  ]

  def initialize(**injected_deps, &block)
    super(**injected_deps)
    add_default_strategies
  end

  def use_reader(template_reader, template_class:)
    @@readers ||= {}

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

    @@readers[template_class] = template_reader
  end

  def read(shell, template)
    reader = @@readers[template.class]

    raise ReaderNotFoundError, "Can't find reader for template #{template}" if reader.nil?

    reader.read(shell, template)
  end

  def reset!
    @@readers = {}
  end

  private
    def add_default_strategies
      use_reader(artifact_file, template_class: KuberKit::Core::Templates::ArtifactFile)
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kuber_kit-0.7.0 lib/kuber_kit/template_reader/reader.rb