Class: MsRestAzure::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/ms_rest_azure/resource.rb

Overview

Class which represents any Azure resource.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idString

Returns the id of the resource.

Returns:

  • (String)

    the id of the resource.



12
13
14
# File 'lib/ms_rest_azure/resource.rb', line 12

def id
  @id
end

#locationString

Returns the location of the resource (required).

Returns:

  • (String)

    the location of the resource (required).



21
22
23
# File 'lib/ms_rest_azure/resource.rb', line 21

def location
  @location
end

#nameString

Returns the name of the resource.

Returns:

  • (String)

    the name of the resource.



15
16
17
# File 'lib/ms_rest_azure/resource.rb', line 15

def name
  @name
end

#tagsHash{String => String}

Returns the tags attached to resources (optional).

Returns:

  • (Hash{String => String})

    the tags attached to resources (optional).



24
25
26
# File 'lib/ms_rest_azure/resource.rb', line 24

def tags
  @tags
end

#typeString

Returns the type of the resource.

Returns:

  • (String)

    the type of the resource.



18
19
20
# File 'lib/ms_rest_azure/resource.rb', line 18

def type
  @type
end

Class Method Details

.deserialize_object(object) ⇒ Resource

Deserializes given hash object into resource.

Parameters:

  • object (Hash)

    resource in hash representation to deserialize.

Returns:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/ms_rest_azure/resource.rb', line 58

def self.deserialize_object(object)
  return if object.nil?
  output_object = Resource.new

  deserialized_property = object['id']
  output_object.id = deserialized_property

  deserialized_property = object['name']
  output_object.name = deserialized_property

  deserialized_property = object['type']
  output_object.type = deserialized_property

  deserialized_property = object['location']
  output_object.location = deserialized_property

  deserialized_property = object['tags']
  output_object.tags = deserialized_property

  output_object.validate
  output_object
end

.serialize_object(object) ⇒ Hash

Serializes given resource object into hash.

Parameters:

  • object (Resource)

    resource object to serialize.

Returns:

  • (Hash)

    hash representation of resource.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ms_rest_azure/resource.rb', line 31

def self.serialize_object(object)
  object.validate
  output_object = {}

  serialized_property = object.id
  output_object['id'] = serialized_property unless serialized_property.nil?

  serialized_property = object.name
  output_object['name'] = serialized_property unless serialized_property.nil?

  serialized_property = object.type
  output_object['type'] = serialized_property unless serialized_property.nil?

  serialized_property = object.location
  output_object['location'] = serialized_property unless serialized_property.nil?

  serialized_property = object.tags
  output_object['tags'] = serialized_property unless serialized_property.nil?

  output_object
end

Instance Method Details

#validateObject

Validates the resource. Throws error if there is any property is incorrect.



84
85
86
# File 'lib/ms_rest_azure/resource.rb', line 84

def validate
  fail MsRest::ValidationError, 'Location cannot be nil in the Resource object' if @location.nil?
end