Sha256: c55d0c2ebe3d01f633a5ebc0f0effc074b72b1b72d8d03107fdbf17beaec1f85

Contents?: true

Size: 1006 Bytes

Versions: 40

Compression:

Stored size: 1006 Bytes

Contents

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

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

  def initialize(**injected_deps)
    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

40 entries across 40 versions & 1 rubygems

Version Path
kuber_kit-0.6.4 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.6.3 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.6.2 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.6.1 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.6.0 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.5.10 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.5.9 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.5.8 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.5.7 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.5.6 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.5.5 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.5.4 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.5.3 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.5.2 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.5.1 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.5.0 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.4.9 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.4.8 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.4.7 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.4.6 lib/kuber_kit/template_reader/reader.rb