Class: Inspec::Profile::AstHelper::InputCollectorOutsideControlBlock

Inherits:
InputCollectorBase show all
Defined in:
lib/inspec/utils/profile_ast_helpers.rb

Constant Summary

Constants inherited from InputCollectorBase

Inspec::Profile::AstHelper::InputCollectorBase::REQUIRED_VALUES_MAP, Inspec::Profile::AstHelper::InputCollectorBase::VALID_INPUT_OPTIONS

Instance Attribute Summary

Attributes inherited from CollectorBase

#memo

Instance Method Summary collapse

Methods inherited from InputCollectorBase

#check_and_collect_input, #collect_input, #extract_node_value, #input_pattern_match?

Constructor Details

#initialize(memo) ⇒ InputCollectorOutsideControlBlock

Returns a new instance of InputCollectorOutsideControlBlock.



364
365
366
# File 'lib/inspec/utils/profile_ast_helpers.rb', line 364

def initialize(memo)
  @memo = memo
end

Instance Method Details

#on_lvasgn(node) ⇒ Object

TODO: There is scope to refactor InputCollectorOutsideControlBlock and InputCollectorWithinControlBlock

  1. We can have a single class for both the collectors
  2. We can have a on_send and on_lvasgn method in the same class :lvasgn in ast stands for "local variable assignment"


372
373
374
375
376
377
378
379
380
381
# File 'lib/inspec/utils/profile_ast_helpers.rb', line 372

def on_lvasgn(node)
  # We are looking for the following pattern in the AST
  # (lvasgn :var_name (send nil? :input ...))
  # example: a = input('a') or a = input('a', value: 'b')
  # and not this: a = 1
  if RuboCop::AST::NodePattern.new("(lvasgn _ (send nil? :input ...))").match(node)
    input_children = node.children[1]
    collect_input(input_children)
  end
end

#on_send(node) ⇒ Object



383
384
385
# File 'lib/inspec/utils/profile_ast_helpers.rb', line 383

def on_send(node)
  check_and_collect_input(node)
end