Class: Aws::Templates::Utils::ArtifactStorage
- 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
-
#[](k) ⇒ Object
Extract object by label.
-
#[]=(k, v) ⇒ Object
Associate label to the object.
-
#artifacts ⇒ Object
(also: #values)
Artifacts list.
- #each(&blk) ⇒ Object
- #each_pair(&blk) ⇒ Object
-
#initialize ⇒ ArtifactStorage
constructor
A new instance of ArtifactStorage.
-
#label?(l) ⇒ Boolean
(also: #key?, #include?)
If the label is present.
-
#labels ⇒ Object
(also: #keys)
Artifacts’ labels list.
- #map(&blk) ⇒ Object
- #reject(&blk) ⇒ Object
-
#search(search_params = {}) ⇒ Object
Find artifacts by criteria.
- #select(&blk) ⇒ Object
Methods included from Enumerable
Methods inherited from Hash
Constructor Details
#initialize ⇒ ArtifactStorage
Returns a new instance of ArtifactStorage.
101 102 103 104 |
# File 'lib/aws/templates/utils/artifact_storage.rb', line 101 def initialize @map = {} @set = Set.new end |
Instance Method Details
#[](k) ⇒ Object
Extract object by label
64 65 66 |
# File 'lib/aws/templates/utils/artifact_storage.rb', line 64 def [](k) @map[k] end |
#[]=(k, v) ⇒ Object
Associate label to the object
70 71 72 73 74 |
# File 'lib/aws/templates/utils/artifact_storage.rb', line 70 def []=(k, v) raise 'nil artifacts are not supported' if v.nil? @set << v unless @set.include?(v) @map[k] = v end |
#artifacts ⇒ Object Also known as: values
Artifacts list
46 47 48 |
# File 'lib/aws/templates/utils/artifact_storage.rb', line 46 def artifacts @set.to_a end |
#each(&blk) ⇒ Object
81 82 83 |
# File 'lib/aws/templates/utils/artifact_storage.rb', line 81 def each(&blk) @map.each(&blk) end |
#each_pair(&blk) ⇒ Object
85 86 87 |
# File 'lib/aws/templates/utils/artifact_storage.rb', line 85 def each_pair(&blk) @map.each_pair(&blk) end |
#label?(l) ⇒ Boolean Also known as: key?, include?
If the label is present
58 59 60 |
# File 'lib/aws/templates/utils/artifact_storage.rb', line 58 def label?(l) @map.key?(l) end |
#labels ⇒ Object Also known as: keys
Artifacts’ labels list
52 53 54 |
# File 'lib/aws/templates/utils/artifact_storage.rb', line 52 def labels @map.keys end |
#map(&blk) ⇒ Object
89 90 91 |
# File 'lib/aws/templates/utils/artifact_storage.rb', line 89 def map(&blk) @map.map(&blk) end |
#reject(&blk) ⇒ Object
97 98 99 |
# File 'lib/aws/templates/utils/artifact_storage.rb', line 97 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
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/aws/templates/utils/artifact_storage.rb', line 32 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
93 94 95 |
# File 'lib/aws/templates/utils/artifact_storage.rb', line 93 def select(&blk) @map.select(&blk) end |