Module: Rudder::DSL::Util
Overview
Utility helper methods for DSL components.
This is ntended for internal use and is subject to change.
Instance Method Summary collapse
-
#_convert_h_val(value, use_name = true) ⇒ Object
Converts non-collections to YAML safe strings and collections to collections of YAML safe strings.
-
#_deep_to_h(hash, use_name = true) ⇒ Hash
Recursively converts keys and values of a Hash to YAML friendly values.
Instance Method Details
#_convert_h_val(value, use_name = true) ⇒ Object
Converts non-collections to YAML safe strings and collections to collections of YAML safe strings
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# 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) ⇒ Hash
Recursively converts keys and values of a Hash to YAML friendly values
20 21 22 23 24 25 26 |
# 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 |