Class: KuberKit::Core::EnvFiles::EnvFileStore

Inherits:
Object
  • Object
show all
Defined in:
lib/kuber_kit/core/env_files/env_file_store.rb

Constant Summary collapse

NotFoundError =
Class.new(KuberKit::NotFoundError)
AlreadyAddedError =
Class.new(KuberKit::Error)

Instance Method Summary collapse

Instance Method Details

#add(env_file) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/kuber_kit/core/env_files/env_file_store.rb', line 5

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

#get(env_file_name) ⇒ Object



19
20
21
22
23
24
# File 'lib/kuber_kit/core/env_files/env_file_store.rb', line 19

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

  env_file
end

#get_from_configuration(env_file_name) ⇒ Object



37
38
39
40
# File 'lib/kuber_kit/core/env_files/env_file_store.rb', line 37

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

#get_global(env_file_name) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/kuber_kit/core/env_files/env_file_store.rb', line 26

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

#reset!Object



42
43
44
# File 'lib/kuber_kit/core/env_files/env_file_store.rb', line 42

def reset!
  @@env_files = {}
end