Method: Inspec::Resources::AzureResourceGroup#method_missing

Defined in:
lib/resources/azure/azure_resource_group.rb

#method_missing(method_id) ⇒ Object

This method catches the xxx_count calls that are made on the resource.

The method that is called is stripped of ‘_count’ and then compared with the mappings table. If that type exists then the number of those items is returned. However if that type is not in the Resource Group then the method will return a NoMethodError exception



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/resources/azure/azure_resource_group.rb', line 99

def method_missing(method_id)
  # Determine the mapping_key based on the method_id
  mapping_key = method_id.to_s.chomp("_count").to_sym

  if mapping.key?(mapping_key)
    # based on the method id get the
    namespace, type_name = mapping[mapping_key].split(/\./)

    # check that the type_name is defined, if not return 0
    if send(namespace).methods.include?(type_name.to_sym)
      # return the count for the method id
      send(namespace).send(type_name)
    else
      0
    end
  else
    msg = format("undefined method `%s` for %s", method_id, self.class)
    raise NoMethodError, msg
  end
end