Class: Sfn::Lint::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/sfn/lint/definition.rb

Overview

Lint defition

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expr, provider = :aws, evaluator = nil, &block) ⇒ self

Create a new definition

Parameters:

  • expr (String)

    search expression used for matching

  • provider (String, Symbol) (defaults to: :aws)

    target provider

  • evaluator (Proc) (defaults to: nil)

    logic used to handle match



21
22
23
24
25
26
27
28
# 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

Instance Attribute Details

#evaluatorProc-ish (readonly)

Returns must respond to #call

Returns:

  • (Proc-ish)

    must respond to #call



11
12
13
# File 'lib/sfn/lint/definition.rb', line 11

def evaluator
  @evaluator
end

#providerSymbol (readonly)

Returns target provider

Returns:

  • (Symbol)

    target provider



13
14
15
# File 'lib/sfn/lint/definition.rb', line 13

def provider
  @provider
end

#search_expressionString (readonly)

Returns search expression used for matching

Returns:

  • (String)

    search expression used for matching



9
10
11
# File 'lib/sfn/lint/definition.rb', line 9

def search_expression
  @search_expression
end

Instance Method Details

#apply(template) ⇒ TrueClass, Array<String>

Apply definition to template

Parameters:

  • template (Hash)

    template being processed

Returns:

  • (TrueClass, Array<String>)

    true if passed. List of string results that failed



34
35
36
37
# File 'lib/sfn/lint/definition.rb', line 34

def apply(template)
  result = JMESPath.search(search_expression, template)
  run(result, template)
end