Class: Inspec::Profile::AstHelper::RefCollector
- Inherits:
-
CollectorBase
- Object
- Parser::AST::Processor
- CollectorBase
- Inspec::Profile::AstHelper::RefCollector
- Defined in:
- lib/inspec/utils/profile_ast_helpers.rb
Instance Attribute Summary
Attributes inherited from CollectorBase
Instance Method Summary collapse
Methods inherited from CollectorBase
Constructor Details
This class inherits a constructor from Inspec::Profile::AstHelper::CollectorBase
Instance Method Details
#on_send(node) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/inspec/utils/profile_ast_helpers.rb', line 179 def on_send(node) if RuboCop::AST::NodePattern.new("(send nil? :ref ...)").match(node) # Construct the array of refs hash as below # "refs": [ # { # "url": "http://", # "ref": "Some ref" # }, # { # "ref": "https://", # } # ] # node.children[1] && node.children[1] == :ref - we don't need this check as the pattern match above will take care of it return unless node.children[2] references = {} if node.children[2].type == :begin # Case for: ref ({:ref=>"Some ref", :url=>"https://"}) # find the hash node iterate_child_and_collect_ref(node.children[2].children, references) elsif node.children[2].type == :str # Case for: ref "ref1", url: "http://", references.merge!(ref: node.children[2].value) iterate_child_and_collect_ref(node.children[3..-1], references) end memo[:refs] ||= [] memo[:refs] << references end end |