Module: XClarityClient::Endpoints::BuildableResourceMixin

Included in:
XclarityEndpoint
Defined in:
lib/xclarity_client/endpoints/buildable_resource_mixin.rb

Overview

A Buildable Resource can build itself from some formats of data (ex: Hashes) and also can transform itself in other formats of data.

Instance Method Summary collapse

Instance Method Details

#build_resource!(attributes) ⇒ Object

Builds the resource from a Hash.

Parameters:

  • attributes (Hash)
    • contains the values

    that will be assign to the resource properties



15
16
17
# File 'lib/xclarity_client/endpoints/buildable_resource_mixin.rb', line 15

def build_resource!(attributes)
  attributes.each { |key, value| set_attr(key, value) }
end

#to_hashHash

Converts the resource into a Hash.

Returns:

  • (Hash)

    containing the resource properties values



24
25
26
27
28
# File 'lib/xclarity_client/endpoints/buildable_resource_mixin.rb', line 24

def to_hash
  hash = {}
  instance_variables.each {|var| hash[var.to_s.delete("@")] = instance_variable_get(var) }
  hash
end