class Sfn::Lint::Definition

Lint defition

Attributes

evaluator[R]

@return [Proc-ish] must respond to call

provider[R]

@return [Symbol] target provider

search_expression[R]

@return [String] search expression used for matching

Public Class Methods

new(expr, provider = :aws, evaluator = nil, &block) click to toggle source

Create a new definition

@param expr [String] search expression used for matching @param provider [String, Symbol] target provider @param evaluator [Proc] logic used to handle match @return [self]

# File lib/sfn/lint/definition.rb, line 21
def initialize(expr, provider = :aws, evaluator = nil, &block)
  if evaluator && block
    raise ArgumentError.new "Only evaluator or block can be provided, not both."
  end
  @provider = Bogo::Utility.snake(provider).to_sym
  @search_expression = expr
  @evaluator = evaluator || block
end

Public Instance Methods

apply(template) click to toggle source

Apply definition to template

@param template [Hash] template being processed @return [TrueClass, Array<String>] true if passed. List of string results that failed

# File lib/sfn/lint/definition.rb, line 34
def apply(template)
  result = JMESPath.search(search_expression, template)
  run(result, template)
end

Protected Instance Methods

run(result, template) click to toggle source

Check result of search expression

@param result [Object] result(s) of search expression @param template [Hash] full template @return [TrueClass, Array<String>] true if passed. List of string results that failed @note override this method when subclassing

# File lib/sfn/lint/definition.rb, line 47
def run(result, template)
  unless evaluator
    raise NotImplementedError.new "No evaluator has been defined for this definition!"
  end
  evaluator.call(result, template)
end