Sha256: ed05c32931034713efd480129d35d548dad87cb9932476afcdd365cb54e05c8b

Contents?: true

Size: 915 Bytes

Versions: 12

Compression:

Stored size: 915 Bytes

Contents

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

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

  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)
    add_default_readers

    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 add_default_readers
    use_reader(artifact_file, env_file_class: KuberKit::Core::EnvFiles::ArtifactFile)
  end

  def reset!
    @@readers = {}
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
kuber_kit-0.2.7 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.2.6 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.2.5 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.2.4 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.2.3 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.2.2 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.2.1 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.2.0 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.1.9 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.1.8 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.1.7 lib/kuber_kit/env_file_reader/reader.rb
kuber_kit-0.1.6 lib/kuber_kit/env_file_reader/reader.rb