Skip to content

Instantly share code, notes, and snippets.

@mattray
Created June 29, 2019 03:48
Show Gist options
  • Save mattray/ced6ceececb72c3c463f1b85167524ec to your computer and use it in GitHub Desktop.
Save mattray/ced6ceececb72c3c463f1b85167524ec to your computer and use it in GitHub Desktop.
File size Foodcritic rule
# check the contents of the directory to see if any of the file are above 1MB
rule "FileSize>1MB", "Contents of files/ is larger than 1MB" do
tags %w{files}
cookbook do |path|
files = File.join(path, "files")
values = []
Dir.foreach(files) do |file|
next if ['.', '..'].member?(file)
size = File.size(File.join(path,'files',file))
if size > 1024*1024 # 1 megabyte
values += [file_match(File.join(path,'files',file))]
end
end
values
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment