class Chef::Provider::Script

Public Class Methods

new(new_resource, run_context) click to toggle source
Calls superclass method Chef::Provider.new
# File lib/chef/provider/script.rb, line 26
def initialize(new_resource, run_context)
  super
  @code = @new_resource.code
end

Public Instance Methods

action_run() click to toggle source
Calls superclass method Chef::Provider::Execute#action_run
# 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() click to toggle source
# File lib/chef/provider/script.rb, line 64
def flags
  @new_resource.flags
end
interpreter() click to toggle source
# File lib/chef/provider/script.rb, line 60
def interpreter
  @new_resource.interpreter
end
script_file() click to toggle source
# File lib/chef/provider/script.rb, line 52
def script_file
  @script_file ||= Tempfile.open("chef-script")
end
set_owner_and_group() click to toggle source
# 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