Sha256: 8d434ef18b776e8e5549461c291937141aa36c6066604875aa8a9f7c1f9dd290

Contents?: true

Size: 1002 Bytes

Versions: 30

Compression:

Stored size: 1002 Bytes

Contents

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

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

  def initialize(**injected_deps)
    super(injected_deps)
    add_default_strategies
  end

  def use_reader(env_file_reader, env_file_class:)
    @@readers ||= {}

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

    @@readers[env_file_class] = env_file_reader
  end

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

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

    reader.read(shell, env_file)
  end

  def reset!
    @@readers = {}
  end

  private
    def add_default_strategies
      use_reader(artifact_file, env_file_class: KuberKit::Core::EnvFiles::ArtifactFile)
    end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
kuber_kit-0.5.5 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.5.4 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.5.3 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.5.2 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.5.1 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.5.0 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.4.9 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.4.8 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.4.7 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.4.6 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.4.5 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.4.4 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.4.3 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.4.2 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.4.1 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.4.0 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.3.11 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.3.10 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.3.9 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.3.8 lib/kuber_kit/env_file_reader/reader.rb