Method: Inspec::Resources::AzureVirtualMachine#method_missing
- Defined in:
- lib/resources/azure/azure_virtual_machine.rb
#method_missing(method_id) ⇒ Object
Method to catch calls that are not explicitly defined. This allows the simple attributes of the virtual machine to be read without having to define each one in turn.
rubocop:disable Metrics/AbcSize
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/resources/azure/azure_virtual_machine.rb', line 40 def method_missing(method_id) # Depending on the method that has been called, determine what value should be returned # These are set as camel case methods to comply with rubocop image_reference_attrs = %w{sku publisher offer} osdisk_attrs = %w{os_type caching create_option disk_size_gb} hardware_profile_attrs = %w{vm_size} os_profile_attrs = %w{computer_name admin_username} osdisk_managed_disk_attrs = %w{storage_account_type} # determine the method name to call by converting the snake_case to camelCase # method_name = self.camel_case(method_id.to_s) method_name = method_id.to_s.split('_').inject([]) { |buffer, e| buffer.push(buffer.empty? ? e : e.capitalize) }.join method_name.end_with?('Gb') ? method_name.gsub!(/Gb/, &:upcase) : false if image_reference_attrs.include?(method_id.to_s) properties.storageProfile.imageReference.send(method_name) elsif osdisk_attrs.include?(method_id.to_s) properties.storageProfile.osDisk.send(method_name) elsif hardware_profile_attrs.include?(method_id.to_s) properties.hardwareProfile.send(method_name) elsif os_profile_attrs.include?(method_id.to_s) properties.osProfile.send(method_name) elsif osdisk_managed_disk_attrs.include?(method_id.to_s) properties.storageProfile.osDisk.managedDisk.send(method_name) end end |