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.



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

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

.syslog_warning(message) ⇒ Object

Syslogs a warning message.

Parameters:

  • message (String)

    The message to log.



74
75
76
# File 'lib/rbeapi/utils.rb', line 74

def self.syslog_warning(message)
  Syslog.open('rbeapi', Syslog::LOG_PID) { |s| s.warning message }
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.



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

def self.transform_keys_to_symbols(value)
  return value unless value.is_a?(Hash)
  hash = value.each_with_object({}) do |(k, v), hsh|
    hsh[k.to_sym] = transform_keys_to_symbols(v)
    hsh
  end
  hash
end