Class: Aws::Templates::Utils::ArtifactStorage

Inherits:
Hash
  • Object
show all
Includes:
Enumerable
Defined in:
lib/aws/templates/utils/artifact_storage.rb

Overview

Arifact storage

It mimics behavior of Hash providing additional ability to search through elements checking for different types of matches:

  • labels

  • classes

  • parameters

It is also able to perform recursive deep search and de-duplication of artifact objects

Instance Method Summary collapse

Methods included from Enumerable

#dependencies, #dependency?

Constructor Details

#initializeArtifactStorage

Returns a new instance of ArtifactStorage.



100
101
102
103
# File 'lib/aws/templates/utils/artifact_storage.rb', line 100

def initialize
  @map = {}
  @set = ::Set.new
end

Instance Method Details

#[](k) ⇒ Object

Extract object by label



63
64
65
# File 'lib/aws/templates/utils/artifact_storage.rb', line 63

def [](k)
  @map[k]
end

#[]=(k, v) ⇒ Object

Associate label to the object



69
70
71
72
73
# File 'lib/aws/templates/utils/artifact_storage.rb', line 69

def []=(k, v)
  raise 'nil artifacts are not supported' if v.nil?
  @set << v unless @set.include?(v)
  @map[k] = v
end

#artifactsObject Also known as: values

Artifacts list



45
46
47
# File 'lib/aws/templates/utils/artifact_storage.rb', line 45

def artifacts
  @set.to_a
end

#each(&blk) ⇒ Object



80
81
82
# File 'lib/aws/templates/utils/artifact_storage.rb', line 80

def each(&blk)
  @map.each(&blk)
end

#each_pair(&blk) ⇒ Object



84
85
86
# File 'lib/aws/templates/utils/artifact_storage.rb', line 84

def each_pair(&blk)
  @map.each_pair(&blk)
end

#label?(l) ⇒ Boolean Also known as: key?, include?

If the label is present

Returns:

  • (Boolean)


57
58
59
# File 'lib/aws/templates/utils/artifact_storage.rb', line 57

def label?(l)
  @map.key?(l)
end

#labelsObject Also known as: keys

Artifacts’ labels list



51
52
53
# File 'lib/aws/templates/utils/artifact_storage.rb', line 51

def labels
  @map.keys
end

#map(&blk) ⇒ Object



88
89
90
# File 'lib/aws/templates/utils/artifact_storage.rb', line 88

def map(&blk)
  @map.map(&blk)
end

#reject(&blk) ⇒ Object



96
97
98
# File 'lib/aws/templates/utils/artifact_storage.rb', line 96

def reject(&blk)
  @map.reject(&blk)
end

#search(search_params = {}) ⇒ Object

Find artifacts by criteria

The method allows flexible introspection of the artifacts enclosed into the storage.

  • search_params - map of search parameters:

** recursive - if true, search will be performed recusrsively

in nested composites

** label - search for artifacts which have the label ** parameters - search for artifacts which have specified

parameters values; it's a multi-level map so
you can check for nested values also


31
32
33
34
35
36
37
38
39
40
41
# File 'lib/aws/templates/utils/artifact_storage.rb', line 31

def search(search_params = {})
  found = filter_artifacts(search_params)

  if search_params[:recursive]
    values
      .select { |object| object.respond_to?(:search) }
      .each { |object| found.concat(object.search(search_params)) }
  end

  found
end

#select(&blk) ⇒ Object



92
93
94
# File 'lib/aws/templates/utils/artifact_storage.rb', line 92

def select(&blk)
  @map.select(&blk)
end