Skip to content

Instantly share code, notes, and snippets.

@sanguis
Last active February 25, 2016 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanguis/8fea8779e61721baeb47 to your computer and use it in GitHub Desktop.
Save sanguis/8fea8779e61721baeb47 to your computer and use it in GitHub Desktop.
# Takes a file and or a url decides if it is a git repo or an archive. # Downloads or clones it. to the destination.
# Takes a file and or a url decides if it is a git repo or an archive.
# Downloads or clones it. to the destination.
# Do not enter url with trailing slash.
def get_files(url, file, destination)
case File.extname(file)
when '.tar.gz', '.zip' then unpack_archive(url, file, destination)
when '.git'
git 'destination' do
repository "#{url}/#{file}"
reference 'master'
user node['apache']['user']
action :sync
end
else fail ArgumentError, "dunno how to handle #{file}"
end
end
def unpack_archive(url, file, destination)
remote_file "#{Chef::Config['file_cache_path'] || '/tmp'}/#{file}" do
owner 'root'
group 'root'
mode '0644'
source "#{url}/#{file}"
not_if File.readable?(file)
end
extract = case File.extname(file)
when '.tar.gz' then "tar-xC #{destination} -f #{file};"
when 'zip' then "unzip -d #{destination} -qo #{file};"
end
bash "Extract #{file}" do
cwd ::File.dirname("#{Chef::Config['file_cache_path'] || '/tmp'}/#{file}")
code extract
not_if { ::File.readable(file) }
end
end
@sanguis
Copy link
Author

sanguis commented Feb 25, 2016

Getting the 3 offenses:

  • libraries/helpers.rb:4:1: C: Method has too many lines. [11/10] def get_files(url, file, destination)
  • libraries/helpers.rb:18:1: C: Assignment Branch Condition size for unpack_archive is too high. [16.52/15] def unpack_archive(url, file, destination)
  • libraries/helpers.rb:18:1: C: Method has too many lines. [16/10] def unpack_archive(url, file, destination)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment