module Rudder::DSL::Util

Utility helper methods for DSL components.

This is ntended for internal use and is subject to change.

Public Instance Methods

_convert_h_val(value, use_name = true) click to toggle source

Converts non-collections to YAML safe strings and collections to collections of YAML safe strings

@param use_name [Boolean] when true named objects

are rendered only by name. Otherwise, renders
to {Hash} (if able), or returns the object itself.
# File lib/rudder/dsl/util.rb, line 36
def _convert_h_val(value, use_name = true)
  case value
  when Array
    value.map { |x| _convert_h_val(x, use_name) }
  when Symbol
    value.to_s
  else
    if use_name && value.respond_to?(:name)
      value.name.to_s
    elsif value.respond_to? :to_h
      _deep_to_h(value.to_h, use_name)
    else
      value
    end
  end
end
_deep_to_h(hash, use_name = true) click to toggle source

Recursively converts keys and values of a {Hash} to YAML friendly values

@param use_name [Boolean] when true named objects

are rendered only by name. Otherwise, renders
to {Hash} (if able), or returns the object itself.

@return [Hash] representation of this class

# File lib/rudder/dsl/util.rb, line 20
def _deep_to_h(hash, use_name = true)
  hash.map do |k, v|
    k = _convert_h_val(k, use_name)
    v = _convert_h_val(v, use_name)
    [k, v]
  end.to_h
end