Class: Chef::Provider::Script

Inherits:
Execute show all
Defined in:
lib/chef/provider/script.rb

Instance Attribute Summary

Attributes inherited from Chef::Provider

#current_resource, #new_resource, #run_context

Instance Method Summary collapse

Methods inherited from Execute

#load_current_resource

Methods included from Mixin::Command

#chdir_or_tmpdir, #handle_command_failures, #not_if, #only_if, #output_of_command, #run_command, #run_command_with_systems_locale

Methods included from Mixin::Command::Windows

#popen4

Methods included from Mixin::Command::Unix

#popen4

Methods inherited from Chef::Provider

#action_nothing, build_from_file, #cookbook_name, #initialize, #load_current_resource, #node, #resource_collection

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename

Methods included from Mixin::RecipeDefinitionDSLCore

#method_missing

Methods included from Mixin::Language

#data_bag, #data_bag_item, #platform?, #search, #value_for_platform

Constructor Details

This class inherits a constructor from Chef::Provider

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Chef::Mixin::RecipeDefinitionDSLCore

Instance Method Details

#action_runObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/chef/provider/script.rb', line 26

def action_run
  script_file.puts(@new_resource.code)
  script_file.close

  set_owner_and_group

  @new_resource.command("\"#{@new_resource.interpreter}\" #{@new_resource.flags} \"#{script_file.path}\"")
  super
ensure
  unlink_script_file
end

#script_fileObject



45
46
47
# File 'lib/chef/provider/script.rb', line 45

def script_file
  @script_file ||= Tempfile.open("chef-script")
end

#set_owner_and_groupObject



38
39
40
41
42
43
# File 'lib/chef/provider/script.rb', line 38

def set_owner_and_group
  # FileUtils itself implements a no-op if +user+ or +group+ are nil
  # You can prove this by running FileUtils.chown(nil,nil,'/tmp/file')
  # as an unprivileged user.
  FileUtils.chown(@new_resource.user, @new_resource.group, script_file.path)
end


49
50
51
# File 'lib/chef/provider/script.rb', line 49

def unlink_script_file
  @script_file && @script_file.close!
end