Class: KuberKit::Core::Artifacts::ArtifactStore

Inherits:
Object
  • Object
show all
Defined in:
lib/kuber_kit/core/artifacts/artifact_store.rb

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#add(artifact) ⇒ Object



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

def add(artifact)
  @@artifacts ||= {}

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

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

  @@artifacts[artifact.name] = artifact
end

#get(artifact_name) ⇒ Object



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

def get(artifact_name)
  artifact = get_from_configuration(artifact_name) || 
             get_global(artifact_name)

  artifact
end

#get_from_configuration(artifact_name) ⇒ Object



37
38
39
40
# File 'lib/kuber_kit/core/artifacts/artifact_store.rb', line 37

def get_from_configuration(artifact_name)
  artifacts = KuberKit.current_configuration.artifacts
  artifacts[artifact_name]
end

#get_global(artifact_name) ⇒ Object



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

def get_global(artifact_name)
  @@artifacts ||= {}
  artifact = @@artifacts[artifact_name]

  if artifact.nil?
    raise NotFoundError, "artifact '#{artifact_name}' not found"
  end
  
  artifact
end

#reset!Object



42
43
44
# File 'lib/kuber_kit/core/artifacts/artifact_store.rb', line 42

def reset!
  @@artifacts = {}
end