# File lib/chef/provider/env.rb, line 72 def action_create if @key_exists if compare_value modify_env Chef::Log.info("#{@new_resource} altered") @new_resource.updated_by_last_action(true) end else create_env Chef::Log.info("#{@new_resource} created") @new_resource.updated_by_last_action(true) end end
# File lib/chef/provider/env.rb, line 115 def action_delete if @key_exists && !delete_element delete_env Chef::Log.info("#{@new_resource} deleted") @new_resource.updated_by_last_action(true) end end
# File lib/chef/provider/env.rb, line 123 def action_modify if @key_exists if compare_value modify_env Chef::Log.info("#{@new_resource} modified") @new_resource.updated_by_last_action(true) end else raise Chef::Exceptions::Env, "Cannot modify #{@new_resource} - key does not exist!" end end
Check to see if value needs any changes
<true> |
If a change is required |
<false> |
If a change is not required |
# File lib/chef/provider/env.rb, line 61 def compare_value if @new_resource.delim #e.g. check for existing value within PATH not @current_resource.value.split(@new_resource.delim).any? do |val| val == @new_resource.value end else @new_resource.value != @current_resource.value end end
# File lib/chef/provider/env.rb, line 135 def create_env raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :#{@new_resource.action}" end
e.g. delete a PATH element
==== Returns <true>:: If we handled the element case and caller should not delete the key <false>:: Caller should delete the key, either no :delim was specific or value was empty after we removed the element.
# File lib/chef/provider/env.rb, line 92 def delete_element return false unless @new_resource.delim #no delim: delete the key if compare_value Chef::Log.debug("#{@new_resource} element '#{@new_resource.value}' does not exist") return true #do not delete the key else new_value = @current_resource.value.split(@new_resource.delim).select { |item| item != @new_resource.value }.join(@new_resource.delim) if new_value.empty? return false #nothing left here, delete the key else old_value = @new_resource.value(new_value) create_env Chef::Log.debug("#{@new_resource} deleted #{old_value} element") @new_resource.updated_by_last_action(true) return true #we removed the element and updated; do not delete the key end end end
# File lib/chef/provider/env.rb, line 139 def delete_env raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :delete" end
# File lib/chef/provider/env.rb, line 52 def env_key_exists(key_name) env_value(key_name) ? true : false end
# File lib/chef/provider/env.rb, line 48 def env_value(key_name) raise Chef::Exceptions::Env, "#{self.to_s} provider does not implement env_value!" end
# File lib/chef/provider/env.rb, line 34 def load_current_resource @current_resource = Chef::Resource::Env.new(@new_resource.name) @current_resource.key_name(@new_resource.key_name) if env_key_exists(@new_resource.key_name) @current_resource.value(env_value(@new_resource.key_name)) else @key_exists = false Chef::Log.debug("#{@new_resource} key does not exist") end @current_resource end
Generated with the Darkfish Rdoc Generator 2.