Sha256: f16eec695c85448dbac0ef9a1f938ed656d4e865fd85285db6198e33642251a4

Contents?: true

Size: 1.09 KB

Versions: 9

Compression:

Stored size: 1.09 KB

Contents

class KuberKit::Core::EnvFiles::EnvFileStore
  NotFoundError = Class.new(KuberKit::NotFoundError)
  AlreadyAddedError = Class.new(KuberKit::Error)

  def add(env_file)
    @@env_files ||= {}

    if !env_file.is_a?(KuberKit::Core::EnvFiles::AbstractEnvFile)
      raise ArgumentError.new("should be an instance of KuberKit::Core::EnvFiles::AbstractEnvFile, got: #{env_file.inspect}")
    end

    unless @@env_files[env_file.name].nil?
      raise AlreadyAddedError, "env_file #{env_file.name} was already added"
    end

    @@env_files[env_file.name] = env_file
  end

  def get(env_file_name)
    env_file = get_from_configuration(env_file_name) || 
               get_global(env_file_name)

    env_file
  end

  def get_global(env_file_name)
    @@env_files ||= {}
    env_file = @@env_files[env_file_name]

    if env_file.nil?
      raise NotFoundError, "env_file '#{env_file_name}' not found"
    end
    
    env_file
  end

  def get_from_configuration(env_file_name)
    env_files = KuberKit.current_configuration.env_files
    env_files[env_file_name]
  end

  def reset!
    @@env_files = {}
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
kuber_kit-0.1.8 lib/kuber_kit/core/env_files/env_file_store.rb
kuber_kit-0.1.7 lib/kuber_kit/core/env_files/env_file_store.rb
kuber_kit-0.1.6 lib/kuber_kit/core/env_files/env_file_store.rb
kuber_kit-0.1.5 lib/kuber_kit/core/env_files/env_file_store.rb
kuber_kit-0.1.4 lib/kuber_kit/core/env_files/env_file_store.rb
kuber_kit-0.1.3 lib/kuber_kit/core/env_files/env_file_store.rb
kuber_kit-0.1.2 lib/kuber_kit/core/env_files/env_file_store.rb
kuber_kit-0.1.1 lib/kuber_kit/core/env_files/env_file_store.rb
kuber_kit-0.1.0 lib/kuber_kit/core/env_files/env_file_store.rb