I'm getting these three 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)
These are all length based offenses. Is there any way to refactor to meet the style guidelines?
# 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