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
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/inspec/utils/profile_ast_helpers.rb', line 204 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 |