Module: Rbeapi::Utils

Defined in:
lib/rbeapi/utils.rb

Overview

Utils module

Class Method Summary collapse

Class Method Details

.class_from_string(name) ⇒ Object

Returns a class object from a string capable of being instatiated

Parameters:

  • :name (String)

    The name of the class to return a constant for

Returns:

  • (Object)

    Returns a a class object that can be instatiated


63
64
65
66
67
# File 'lib/rbeapi/utils.rb', line 63

def self.class_from_string(name)
  name.split('::').inject(Object) do |mod, cls|
    mod.const_get(cls)
  end
end

.transform_keys_to_symbols(value) ⇒ Hash

Iterates through a hash structure and converts all of the keys to symbols.

Parameters:

  • :value (Hash)

    The hash structure to convert the keys

Returns:

  • (Hash)

    An updated hash structure with all keys converted to symboles


48
49
50
51
52
53
54
55
# File 'lib/rbeapi/utils.rb', line 48

def self.transform_keys_to_symbols(value)
  return value if not value.kind_of?(Hash)
  hash = value.inject({}) do |hsh, (k,v)|
    hsh[k.to_sym] = self.transform_keys_to_symbols(v)
    hsh
  end
  hash
end