lib/builderator/util.rb in builderator-0.3.14 vs lib/builderator/util.rb in builderator-0.3.15
- old
+ new
@@ -11,23 +11,17 @@
{}.tap { |tt| aws_tags.each { |t| tt[t.key.to_s] = t.value } }
end
def filter(resources, filters = {})
resources.select do |_, r|
- filters.reduce(true) do |memo, (k, v)|
- memo && r[:properties].include?(k.to_s) &&
- r[:properties][k.to_s] == v
- end
+ _filter_reduce(r, filters)
end
end
def filter!(resources, filters = {})
resources.select! do |_, r|
- filters.reduce(true) do |memo, (k, v)|
- memo && r[:properties].include?(k.to_s) &&
- r[:properties][k.to_s] == v
- end
+ _filter_reduce(r, filters)
end
resources
end
@@ -44,9 +38,22 @@
@asg ||= Aws::AutoScaling::Client.new(:region => region)
end
def working_dir(relative = '.')
Pathname.pwd.join(relative).expand_path
+ end
+
+ private
+
+ def _filter_reduce(resource, filters)
+ filters.reduce(true) do |memo, (k, v)|
+ ## Allow for negation with a leading `~`
+ if v[0] == '~'
+ memo && (!resource[:properties].include?(k.to_s) || resource[:properties][k.to_s] != v[1..-1])
+ else
+ memo && resource[:properties].include?(k.to_s) && resource[:properties][k.to_s] == v
+ end
+ end
end
end
end
end