class RuboCop::Cop::Chef::Correctness::TmpPath

Use file_cache_path rather than hard-coding system temp paths

@example downloading a large file into /tmp/

#### incorrect
remote_file '/tmp/large-file.tar.gz' do

#### correct
remote_file "#{Chef::Config[:file_cache_path]}/large-file.tar.gz" do

Constants

MSG
RESTRICT_ON_SEND

Public Instance Methods

file_cache_path?(path) click to toggle source
# File lib/rubocop/cop/chef/correctness/tmp_path.rb, line 51
def file_cache_path?(path)
  path_str = path.to_s.scan(/"(.*)"/)[0][0]
  path_str.start_with?("\#\{Chef::Config[:file_cache_path]\}")
end
hardcoded_tmp?(path) click to toggle source
# File lib/rubocop/cop/chef/correctness/tmp_path.rb, line 46
def hardcoded_tmp?(path)
  path_str = path.to_s.scan(/"(.*)"/)[0][0]
  path_str.start_with?('/tmp/')
end
on_send(node) click to toggle source
# File lib/rubocop/cop/chef/correctness/tmp_path.rb, line 39
def on_send(node)
  remote_file?(node) do |command|
    return unless hardcoded_tmp?(command) && !file_cache_path?(command)
    add_offense(command, message: MSG, severity: :refactor)
  end
end