Sha256: 05ad05faf0244195a1dcd955ad3ab7cb307fb4ce6109451b0de9c45341209191

Contents?: true

Size: 926 Bytes

Versions: 18

Compression:

Stored size: 926 Bytes

Contents

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

  include KuberKit::Import[
    "template_reader.artifact_file_reader",
  ]

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

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

    @@readers[template_class] = template_reader
  end

  def read(shell, template)
    add_default_readers

    reader = @@readers[template.class]

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

    reader.read(shell, template)
  end

  def add_default_readers
    use_reader(artifact_file_reader, template_class: KuberKit::Core::Templates::ArtifactFile)
  end

  def reset!
    @@readers = {}
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
kuber_kit-0.2.7 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.2.6 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.2.5 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.2.4 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.2.3 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.2.2 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.2.1 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.2.0 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.1.9 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.1.8 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.1.7 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.1.6 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.1.5 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.1.4 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.1.3 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.1.2 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.1.1 lib/kuber_kit/template_reader/reader.rb
kuber_kit-0.1.0 lib/kuber_kit/template_reader/reader.rb