Class: AzureResourceDynamicMethods

Inherits:
Object
  • Object
show all
Defined in:
lib/resources/azure/azure_backend.rb

Overview

Class to create methods on the calling object at run time. Each of the Azure Resources have different attributes and properties, and they all need to be testable. To do this no methods are hardcoded, each on is craeted based on the information returned from Azure.

The class is a helper class essentially as it creates the methods on the calling class rather than itself. This means that there is less duplication of code and it can be reused easily.

Author:

  • Russell Seymour

Since:

  • 0.2.0

Instance Method Summary collapse

Instance Method Details

#create_methods(object, data) ⇒ Object

Given the calling object and its data, create the methods on the object according to the data that has been retrieved. Various types of data can be returned so the method checks the type to ensure that the necessary methods are configured correctly

Parameters:

  • AzureResourceProbe|AzureResource

    object The object on which the methods should be craeted

  • variant

    data The data from which the methods should be created

Since:

  • 0.2.0



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/resources/azure/azure_backend.rb', line 202

def create_methods(object, data)
  # Check the type of data as this affects the setup of the methods
  # If it is an Azure Generic Resource then setup methods for each of
  # the instance variables
  case data.class.to_s
  when /^Azure::Resources::Mgmt::.*::Models::GenericResource$/,
       /^Azure::Resources::Mgmt::.*::Models::ResourceGroup$/
    # iterate around the instance variables
    data.instance_variables.each do |var|
      create_method(object, var.to_s.delete("@"), data.instance_variable_get(var))
    end
  # When the data is a Hash object iterate around each of the key value pairs and
  # craete a method for each one.
  when "Hash"
    data.each do |key, value|
      create_method(object, key, value)
    end
  end
end