lib/sfn/lint/rule.rb in sfn-3.0.28 vs lib/sfn/lint/rule.rb in sfn-3.0.30
- old
+ new
@@ -19,11 +19,11 @@
# @param name [String, Symbol] name of rule
# @param definitions [Array<Definition>] definitions composing rule
# @param fail_message [String] message to describe failure
# @param provider [String, Symbol] target provider
# @return [self]
- def initialize(name, definitions, fail_message, provider=:aws)
+ def initialize(name, definitions, fail_message, provider = :aws)
@name = name.to_sym
@definitions = definitions.dup.uniq.freeze
@fail_message = fail_message
@provider = Bogo::Utility.snake(provider).to_sym
validate_definitions!
@@ -31,17 +31,17 @@
# Generate the failure message for this rule with given failure
# result set.
def generate_fail_message(results)
msg = fail_message.dup
- unless(results.empty?)
+ unless results.empty?
failed_items = results.map do |item|
f_item = item[:failures]
next if f_item.nil? || f_item == true || f_item == false
f_item
end.flatten.compact.map(&:to_s)
- unless(failed_items.empty?)
+ unless failed_items.empty?
msg = "#{msg} (failures: `#{failed_items.join('`, `')}`)"
end
end
msg
end
@@ -53,14 +53,14 @@
def apply(template)
results = definitions.map do |definition|
result = definition.apply(template)
result == true ? result : Smash.new(:definition => definition, :failures => result)
end
- if(results.all?{|item| item == true})
+ if results.all? { |item| item == true }
true
else
- results.delete_if{|item| item == true}
+ results.delete_if { |item| item == true }
results
end
end
# Check if template passes this rule
@@ -105,14 +105,13 @@
# Check that provided definitions provider match rule defined provider
def validate_definitions!
non_match = definitions.find_all do |definition|
definition.provider != provider
end
- unless(non_match.empty?)
+ unless non_match.empty?
raise ArgumentError.new "Rule defines `#{provider}` as provider but includes definitions for " \
- "non matching providers. (#{non_match.map(&:provider).map(&:to_s).uniq.sort.join(', ')})"
+ "non matching providers. (#{non_match.map(&:provider).map(&:to_s).uniq.sort.join(', ')})"
end
end
-
end
end
end