lib/ridley/chef_objects/environment_object.rb in ridley-1.6.0 vs lib/ridley/chef_objects/environment_object.rb in ridley-1.7.0
- old
+ new
@@ -52,7 +52,53 @@
# @return [Hashie::Mash]
def set_override_attribute(key, value)
attr_hash = Hashie::Mash.from_dotted_path(key, value)
self.override_attributes = self.override_attributes.deep_merge(attr_hash)
end
+
+ # Removes a environment default attribute given its dotted path
+ # representation. Returns the default attributes of the environment.
+ #
+ # @param [String] key
+ # the dotted path to an attribute
+ #
+ # @return [Hashie::Mash]
+ def delete_default_attribute(key)
+ delete_attribute(key, :default)
+ end
+
+ # Removes a environment override attribute given its dotted path
+ # representation. Returns the override attributes of the environment.
+ #
+ # @param [String] key
+ # the dotted path to an attribute
+ #
+ # @return [Hashie::Mash]
+ def delete_override_attribute(key)
+ delete_attribute(key, :override)
+ end
+
+ private
+
+ # Deletes an attribute at the given precedence using its dotted-path key.
+ #
+ # @param [String] key
+ # the dotted path to an attribute
+ # @param [Symbol] precedence
+ # the precedence level to delete the attribute from
+ #
+ # @return [Hashie::Mash]
+ def delete_attribute(key, precedence)
+ dotted_path = key.split('.')
+ leaf_key = dotted_path.pop
+ case precedence
+ when :default
+ attributes_to_change = self.default_attributes
+ when :override
+ attributes_to_change = self.override_attributes
+ end
+ leaf_hash = dotted_path.inject(attributes_to_change) { |hash, element| hash[element] }
+ leaf_hash.delete(leaf_key) unless leaf_hash.nil?
+ attributes_to_change
+ end
end
end