class Aws::Templates::Utils::ArtifactStorage
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
Public Class Methods
new()
click to toggle source
# File lib/aws/templates/utils/artifact_storage.rb, line 100 def initialize @map = {} @set = ::Set.new end
Public Instance Methods
[](k)
click to toggle source
Extract object by label
# File lib/aws/templates/utils/artifact_storage.rb, line 63 def [](k) @map[k] end
[]=(k, v)
click to toggle source
Associate label to the object
# 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
artifacts()
click to toggle source
Artifacts list
# File lib/aws/templates/utils/artifact_storage.rb, line 45 def artifacts @set.to_a end
Also aliased as: values
each(&blk)
click to toggle source
# File lib/aws/templates/utils/artifact_storage.rb, line 80 def each(&blk) @map.each(&blk) end
each_pair(&blk)
click to toggle source
# File lib/aws/templates/utils/artifact_storage.rb, line 84 def each_pair(&blk) @map.each_pair(&blk) end
label?(l)
click to toggle source
If the label is present
# File lib/aws/templates/utils/artifact_storage.rb, line 57 def label?(l) @map.key?(l) end
labels()
click to toggle source
Artifacts' labels list
# File lib/aws/templates/utils/artifact_storage.rb, line 51 def labels @map.keys end
Also aliased as: keys
map(&blk)
click to toggle source
# File lib/aws/templates/utils/artifact_storage.rb, line 88 def map(&blk) @map.map(&blk) end
reject(&blk)
click to toggle source
# File lib/aws/templates/utils/artifact_storage.rb, line 96 def reject(&blk) @map.reject(&blk) end
search(search_params = {})
click to toggle source
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
# 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)
click to toggle source
# File lib/aws/templates/utils/artifact_storage.rb, line 92 def select(&blk) @map.select(&blk) end
Private Instance Methods
check_parameters(object, params)
click to toggle source
# File lib/aws/templates/utils/artifact_storage.rb, line 126 def check_parameters(object, params) params.all? do |name, value| if object.respond_to?(name) if value.respond_to?(:to_hash) check_parameters(object.send(name), value.to_hash) else object.send(name) == value end end end end
filter_artifacts(search_params)
click to toggle source
# File lib/aws/templates/utils/artifact_storage.rb, line 107 def filter_artifacts(search_params) found = filter_by_label(search_params[:label]) klass = search_params[:klass] params_match = search_params[:parameters] found = found.select { |object| object.is_a?(klass) } if klass found = found.select { |object| check_parameters(object, params_match) } if params_match found end
filter_by_label(label)
click to toggle source
# File lib/aws/templates/utils/artifact_storage.rb, line 119 def filter_by_label(label) return values if label.nil? return [] unless key?(label) [self[label]] end