class Ridley::EnvironmentObject
Public Instance Methods
Set an environment level default attribute given the dotted path representation of the Chef
attribute and value
@example setting and saving an environment level default attribute
obj = environment.find("production") obj.set_default_attribute("my_app.billing.enabled", false) obj.save
@param [String] key @param [Object] value
@return [Hashie::Mash]
# File lib/ridley/chef_objects/environment_object.rb, line 35 def set_default_attribute(key, value) attr_hash = Hashie::Mash.from_dotted_path(key, value) self.default_attributes = self.default_attributes.deep_merge(attr_hash) end
Set an environment level override attribute given the dotted path representation of the Chef
attribute and value
@example setting and saving an environment level override attribute
obj = environment.find("production") obj.set_override_attribute("my_app.billing.enabled", false) obj.save
@param [String] key @param [Object] value
@return [Hashie::Mash]
# File lib/ridley/chef_objects/environment_object.rb, line 53 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]
# File lib/ridley/chef_objects/environment_object.rb, line 65 def unset_default_attribute(key) unset_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]
# File lib/ridley/chef_objects/environment_object.rb, line 77 def unset_override_attribute(key) unset_attribute(key, :override) end
Private Instance Methods
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]
# File lib/ridley/chef_objects/environment_object.rb, line 92 def unset_attribute(key, precedence) keys = key.split(".") leaf_key = keys.pop attributes_to_change = case precedence when :default self.default_attributes when :override self.override_attributes end leaf_attributes = keys.inject(attributes_to_change) do |attributes, key| if attributes[key] && attributes[key].kind_of?(Hashie::Mash) attributes = attributes[key] else return attributes_to_change end end leaf_attributes.delete(leaf_key) return attributes_to_change end