Sha256: 7c1c56b06ae27fd853507b3bb8daada620fd5a3d19e6aa9e2b643df6c3a23ad1

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

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

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

  def initialize(**injected_deps, &block)
    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)
      use_reader(env_group, env_file_class: KuberKit::Core::EnvFiles::EnvGroup)
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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