Module: Bosh::Template::PropertyHelper
- Included in:
- EvaluationContext, EvaluationLink, EvaluationLinkInstance
- Defined in:
- lib/bosh/template/property_helper.rb
Instance Method Summary collapse
-
#copy_property(dst, src, name, default = nil) ⇒ Object
Copies property with a given name from src to dst.
- #lookup_property(collection, name) ⇒ Object
Instance Method Details
#copy_property(dst, src, name, default = nil) ⇒ Object
Copies property with a given name from src to dst.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/bosh/template/property_helper.rb', line 11 def copy_property(dst, src, name, default = nil) keys = name.split(".") src_ref = src dst_ref = dst keys.each do |key| unless src_ref.is_a?(Hash) raise Bosh::Template::InvalidPropertyType, "Property '#{name}' expects a hash, but received '#{src_ref.class}'" end src_ref = src_ref[key] break if src_ref.nil? # no property with this name is src end keys[0..-2].each do |key| dst_ref[key] ||= {} dst_ref = dst_ref[key] end dst_ref[keys[-1]] ||= {} dst_ref[keys[-1]] = src_ref.nil? ? default : src_ref end |
#lookup_property(collection, name) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/bosh/template/property_helper.rb', line 36 def lookup_property(collection, name) return nil if collection.nil? keys = name.split(".") ref = collection keys.each do |key| ref = ref[key] return nil if ref.nil? end ref end |