Class: Chef::Provider::Script
- Inherits:
-
Execute
- Object
- Chef::Provider
- Execute
- Chef::Provider::Script
- Defined in:
- lib/chef/provider/script.rb
Direct Known Subclasses
Constant Summary
Constants included from Mixin::ShellOut
Mixin::ShellOut::DEPRECATED_OPTIONS
Instance Attribute Summary
Attributes inherited from Chef::Provider
#action, #current_resource, #new_resource, #run_context
Instance Method Summary collapse
- #action_run ⇒ Object
- #flags ⇒ Object
-
#initialize(new_resource, run_context) ⇒ Script
constructor
A new instance of Script.
- #interpreter ⇒ Object
- #script_file ⇒ Object
- #set_owner_and_group ⇒ Object
- #unlink_script_file ⇒ Object
Methods inherited from Execute
#load_current_resource, #whyrun_supported?
Methods included from Mixin::ShellOut
#run_command_compatible_options, #shell_out, #shell_out!
Methods inherited from Chef::Provider
#action_nothing, #cleanup_after_converge, #converge_by, #cookbook_name, #define_resource_requirements, #events, #load_current_resource, #node, #process_resource_requirements, #requirements, #resource_collection, #resource_updated?, #run_action, #set_updated_status, #whyrun_mode?, #whyrun_supported?
Methods included from DSL::Recipe
Methods included from Mixin::ConvertToClassName
#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename
Constructor Details
#initialize(new_resource, run_context) ⇒ Script
Returns a new instance of Script.
26 27 28 29 |
# File 'lib/chef/provider/script.rb', line 26 def initialize(new_resource, run_context) super @code = @new_resource.code end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Chef::DSL::Recipe
Instance Method Details
#action_run ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/chef/provider/script.rb', line 31 def action_run script_file.puts(@code) script_file.close set_owner_and_group @new_resource.command("\"#{interpreter}\" #{flags} \"#{script_file.path}\"") super converge_by(nil) do # ensure script is unlinked at end of converge! unlink_script_file end end |
#flags ⇒ Object
64 65 66 |
# File 'lib/chef/provider/script.rb', line 64 def flags @new_resource.flags end |
#interpreter ⇒ Object
60 61 62 |
# File 'lib/chef/provider/script.rb', line 60 def interpreter @new_resource.interpreter end |
#script_file ⇒ Object
52 53 54 |
# File 'lib/chef/provider/script.rb', line 52 def script_file @script_file ||= Tempfile.open("chef-script") end |
#set_owner_and_group ⇒ Object
45 46 47 48 49 50 |
# File 'lib/chef/provider/script.rb', line 45 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 |
#unlink_script_file ⇒ Object
56 57 58 |
# File 'lib/chef/provider/script.rb', line 56 def unlink_script_file @script_file && @script_file.close! end |