Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/softlayer/object_mask_helpers.rb

Overview

This extension to the Hash class to allows object masks to be constructed from built-in Ruby types and converted to object masks strings for presentation to the SoftLayer API

Instance Method Summary collapse

Instance Method Details

#_to_sl_object_mask_propertyObject

Returns a string representing the hash as a property within a larger object mask. This routine is an implementation detail used in the conversion of hashes to object mask strings. You should not have to call this method directly.



29
30
31
32
# File 'lib/softlayer/object_mask_helpers.rb', line 29

def _to_sl_object_mask_property()
  key_strings = __sl_object_mask_properties_for_keys();
  "#{key_strings.join(',')}"
end

#to_sl_object_maskObject

Given a hash, generate an Object Mask string from the structure found within the hash. This allows object masks to be constructed as hashes, then converted to strings when they must be passed to the API. The routine does some very rudimentary validation to ensure that the hash represents a valid object mask, but care must still be taken when constructing the hash.

Raises:

  • (RuntimeError)


18
19
20
21
22
23
24
# File 'lib/softlayer/object_mask_helpers.rb', line 18

def to_sl_object_mask()
  raise RuntimeError, "An object mask must contain properties" if empty?
  raise RuntimeError, "An object mask must start with root properties" if keys().find { |key| !__valid_root_property_key?(key) }

  key_strings = __sl_object_mask_properties_for_keys();
  key_strings.count > 1 ? "[#{key_strings.join(',')}]" : "#{key_strings[0]}"
end