Class: Inspec::Profile::AstHelper::InputCollectorOutsideControlBlock
- Inherits:
-
InputCollectorBase
- Object
- Parser::AST::Processor
- CollectorBase
- InputCollectorBase
- Inspec::Profile::AstHelper::InputCollectorOutsideControlBlock
- 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
Instance Method Summary collapse
-
#initialize(memo) ⇒ InputCollectorOutsideControlBlock
constructor
A new instance of InputCollectorOutsideControlBlock.
-
#on_lvasgn(node) ⇒ Object
TODO: There is scope to refactor InputCollectorOutsideControlBlock and InputCollectorWithinControlBlock 1.
- #on_send(node) ⇒ Object
Methods inherited from InputCollectorBase
#check_and_collect_input, #collect_input, #input_pattern_match?
Constructor Details
#initialize(memo) ⇒ InputCollectorOutsideControlBlock
Returns a new instance of InputCollectorOutsideControlBlock.
336 337 338 |
# File 'lib/inspec/utils/profile_ast_helpers.rb', line 336 def initialize(memo) @memo = memo end |
Instance Method Details
#on_lvasgn(node) ⇒ Object
TODO: There is scope to refactor InputCollectorOutsideControlBlock and InputCollectorWithinControlBlock
-
We can have a single class for both the collectors
-
We can have a on_send and on_lvasgn method in the same class
:lvasgn in ast stands for “local variable assignment”
344 345 346 347 348 349 350 351 352 353 |
# File 'lib/inspec/utils/profile_ast_helpers.rb', line 344 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
355 356 357 |
# File 'lib/inspec/utils/profile_ast_helpers.rb', line 355 def on_send(node) check_and_collect_input(node) end |